我需要像这样创建一个左上角和左下角半径的按钮
.我尝试创建以下扩展,取自stackoverflow之一:
extension UIButton {
func roundCorners(corners:UIRectCorner, radius: CGFloat) {
self.layer.borderColor = GenerateShape.UIColorFromHex(0x989898, alpha: (1.0-0.3)).CGColor
self.layer.borderWidth = 1.0
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
self.layer.mask = mask
}
}
Run Code Online (Sandbox Code Playgroud)
然后调用这样的方法:
self.collectionBtn.roundCorners(.TopLeft | .BottomLeft, radius: cornerRadius)
Run Code Online (Sandbox Code Playgroud)
那么为什么左上角和左下角看不见呢?我该怎么办才能让它们可见?
我有一个复杂的HTML文档,有这么多标题,可以HTMLAgilityPack一次性选择所有标题查询?结果应该保持标题的原始序列.
有谁知道这个?谢谢
我发现Swagger可以为我开发的Restful Api生成文档,但是问题是我只使用Flask而不是flask-restful,当我尝试使用flask-restful-swagger包装器时,它不起作用,因为像这样的例子:
from sqlalchemy.orm import create_session
from flask import Flask, request, jsonify
from Model import *
from flask_restful import Api
from flask_restful_swagger import swagger
app = Flask(__name__)
api = swagger.docs(Api(app), apiVersion='0.1', api_spec_url="/api/spec")
session = create_session(bind=engine)
@app.route('/employees/', methods=['GET'])
@swagger.operation(
parameters=[
{
"name": "body",
"description": "Get the employees in the shop.",
"required": True,
"allowMultiple": False,
"dataType": NsEmployee.__name__,
"paramType": "body"
}
],
responseMessages=[
{
"code": 201,
"message": "Created. The URL of the created blueprint should appear in the Location header"
},
{
"code": …Run Code Online (Sandbox Code Playgroud) 我正在尝试打开我UITextView在应用程序中识别的链接.我正在使用该UITextView delegate方法shouldInteractWithURL来实现这一目标.
我的代码似乎适用于app的app加载; 但是,除了应用程序之外,它仍然在Safari中打开链接.有没有什么办法解决这一问题?
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
println("called")
let webViewController = WebViewController()
webViewController.urlToLoad = URL
if let navigationController = navigationController {
println("navigating")
navigationController.pushViewController(webViewController, animated: true)
return true
}
else {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,这WebViewController只是我制作的一个自定义类,它显示UIWebView整个屏幕.它有一个属性urlToLoad,它将在其中加载的URL UIWebView.
我也分配delegate的UITextView到UIViewController已经在实施这个代理功能.
有谁知道如何让应用程序停止开放野生动物园?
我想在资产文件夹中显示几个图像到我的应用程序中.所以我想做一个页面视图.
首先,图像将在集合视图内,然后单击,图像将全屏显示.然后,用户可以通过向右和向左滑动来在图像之间滑动,如下图所示:

我找到了这个教程:
更新:
我在故事板中有这个:

现在,GaleryViewController我在细胞中显示图像
当用户点击它时,我将全屏打开图像PhotoViewController.
PhotoViewController.swift:
import UIKit
class PhotoViewController: UIViewController{
@IBOutlet weak var imageView: UIImageView!
var index: Int = 0;
var pageViewController : UIPageViewController?
@IBAction func btnCancelClicked(sender: AnyObject) {
self.navigationController?.popToRootViewControllerAnimated(true);
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
initUI();
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(animated: Bool) {
self.navigationController?.hidesBarsOnTap …Run Code Online (Sandbox Code Playgroud) bounds.size.width和bounds.widthswift有什么区别?他们会返回同样的东西吗?谢谢!
我试图从一个视图控制器转到另一个视图控制器,并将数据传递给下一个控制器。但我不断收到此错误:
Could not cast value of type 'UITableViewController' to 'UINavigationController'
Run Code Online (Sandbox Code Playgroud)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "segueLogWaterData") {
// pass data to next view
let nav = segue.destinationViewController as! UINavigationController
let segueViewController = nav.topViewController as! WaterDataViewController
}
}
Run Code Online (Sandbox Code Playgroud)
这发生在WaterDataViewController作为UITableViewController. 我也试过嵌入WaterDataViewController到 aUINavigationController但我得到了类似的错误:
Could not cast value of type 'UITableViewController' to 'MyApp.WaterDataViewController'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我在Playground中得到了这段代码:
func throwsError() throws{
var x = [1,2]
print(x[3])
}
func start(){
do{
try throwsError()
}
catch let unknown{
"unknown: \(unknown)"
}
}
start()
Run Code Online (Sandbox Code Playgroud)
所以很明显这个'throwsError函数会抛出一个错误:
执行被中断,原因是:EXC_BAD_INSTRUCTION
有没有办法抓住这个?我在线阅读为Array类编写一个下标,它总是检查范围,但问题更大:我不能抓住任何东西吗?
我有UICollectionView142个细胞.任何时候都可以看到7.5.
我正在将一个单元格从indexPath0移到100.但我也想滚动到那个新位置.
下面的代码工作正常.但它动画移动和滚动,但随后将细胞加载到中央/移动的细胞前后.我认为这是因为细胞是可重复使用的.但是142,我无法预加载所有这些
它不是最好的效果,我想预先加载新位置周围的单元格,4之前和之后4 indexPath,然后看动画的动画和滚动.你能帮帮忙吗?
UIView.animateWithDuration(animationSpeed, animations: {() -> Void in
self.collectionView.layoutIfNeeded()
self.collectionView.scrollToItemAtIndexPath(NSIndexPath(forItem:self.indexPathSelected.row,
inSection:0),
atScrollPosition: .CenteredHorizontally,
animated: true)
})
Run Code Online (Sandbox Code Playgroud) animation scroll uicollectionview uicollectionreusableview swift
我刚开始编码Swift,我有以下解析 JSON 的代码
func parse (latitude: Double, longtitude: Double){
let jsonUrlString = "https://api.darksky.net/forecast/apiKey/\(latitude),\(longtitude)"
guard let url = URL(string: jsonUrlString) else{
return
}
var information: forecast?
URLSession.shared.dataTask(with: url) { (data, res, err) in
guard let data = data else {
return
}
do {
let json = try JSONDecoder().decode(forecast.self, from: data)
self.info = json
} catch {
print("didnt work")
}
}.resume()
processJson(info)
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我想将存储在 JSON 中的数据传递给要使用processJson函数处理的类中的变量,但是由于 dataTask 函数不返回任何值,并且 JSON 变量是本地存储的,因此我无法在类之外处理 info 变量(它总是返回零)。我想知道这个问题的解决方案是什么?我面临同样的问题weather.getCoordinate()。