Tag: swift

在Swift IOS中的UIButton查询

我有一个62,62平方的button。 我有一个40,40平方的形象。 我想在button中的图像(这是很容易和完成),但我希望它在button框架的顶部,我想在底部的一些文字。 所以看起来像这样: 任何想法如何迅速做到这一点? 我到目前为止: button.backgroundColor = UIColor(red: 0.13, green: 0.48, blue: 0.81, alpha: 1.0) button.tag = i button.imageView?.image button.setImage(image, forState: .Normal) button.setTitle("Test", forState: UIControlState.Normal) testingsetTitle,作为…forms来到图像的右侧。 任何人都可以build议?

parsingSwift IOS – PFCloud callFunctionInBackgroundselect器未被调用

当我从正常调用PFcloud函数返回正确的计数如何,当我调用select器,select器callback函数不会被触发, 欣赏是否有任何可以指向我什么是我的代码中的错误。 工作模块 – 成功打印计数 PFCloud.callFunctionInBackground(CloudFunctions.getBookingCount, withParameters: ["camp": "pmAwLDTNc6"], block: { (result: AnyObject!, error: NSError!) -> Void in if ( error === nil) { NSLog("Booking Count call back: \(result) ") } else if (error != nil) { NSLog("error in helloWorld: \(error.userInfo)") } }) 不工作块(select器) – select器function未被调用 PFCloud.callFunctionInBackground(CloudFunctions.getBookingCount, withParameters: ["camp": "pmAwLDTNc6"], target: self, selector: "block:") func […]

当设备被locking时,将文件加载到今日分机中

在我的今天扩展与我的设备解锁,这一行代码按预期工作,从图像path返回数据: let imageData = NSData(contentsOfFile: path) 但是,当我的设备被locking密码,它返回零。 设备locking时,有没有办法访问文件系统中的图像? 我可以很好地访问UserDefaults,但不能访问共享组的目录中的文件。 这里是我如何创buildpath,调用imagePath ,正确填充我期望在这两种情况下的path: func rootFilePath() -> String? { let manager = NSFileManager() let containerURL = manager.containerURLForSecurityApplicationGroupIdentifier(GROUP_ID) if let unwrappedURL = containerURL { return unwrappedURL.path } else { return nil } } func imagePath() -> String? { let rootPath = rootFilePath() if let uPath = rootPath { return […]

在Swift中遍历视图控制器层次结构

我想遍历Swift中的视图控制器层次结构,并find一个特定的类。 这里是代码: extension UIViewController{ func traverseAndFindClass<T : UIViewController>() -> UIViewController?{ var parentController = self.parentViewController as? T? ^ | | // Error: Could not find a user-defined conversion from type 'UIViewController?' to type 'UIViewController' while(parentController != nil){ parentController = parentController!.parentViewController } return parentController } } 现在,我知道parentViewController属性返回一个可选的UIViewController,但我不知道如何在上帝的名字,我可以使通用一个可选的types。 也许使用某种where子句?

parsing和Facebooklogin和注册返回“用户已取消login”(iOS 8.1 + Swift 1.2)

我一直试图使用Parse(版本1.7.4)login并使用Facebook的SDK(版本4.1)注册用户,但每次我尝试注册时,下面的代码打印出“用户取消的FBlogin”,这意味着用户被返回为零,但没有错误。 我不知道这是一个parsing问题还是一个Facebook问题,但是如果有人有任何想法可以解决这个问题,我会非常感激。 这是我的login/注册视图控制器的代码: let permissions = [ "email","user_birthday", "public_profile", "user_friends"] @IBOutlet weak var lblStatus: UILabel! @IBAction func facebookLoginDidPress(sender: AnyObject) { self.lblStatus.alpha = 0 PFFacebookUtils.logInInBackgroundWithReadPermissions(self.permissions, block: { (user: PFUser?, error: NSError?) -> Void in if user == nil { if error == nil { println("User cancelled FB login") self.lblStatus.text = "User cancelled login" self.lblStatus.alpha = 1 […]

IBOutlet属性返回“Can not unwrap Optional.None”错误

我遇到了一些代码,在我的代码中带有可怕的“Can not unwrap Optional.None”错误。 我正在关注iTunes U斯坦福大学的Shutterbug代码。 这是Objective-C为其中一个类提供的代码。 http://pastebin.com/LG2k3BBW 和我在Swift中提出的一样。 http://pastebin.com/pGtSzu6z 在追查这些错误之后,这些线路似乎给我带来了问题 self.scrollView.zoomScale = 1.0 和 self.image = nil 有什么问题在这里的任何意见? 我最初把所有的setter放在ViewDidLoad函数中,并且收到了同样的错误。

基于UIImage大小捕获屏幕

我有捕获自定义视图的问题。 我正在设置大小UIImage图像数据的大小捕获的图像,但是当我把截图的图像是这样的! : 图像缩小! 这里是代码: UIGraphicsBeginImageContextWithOptions((self.photoImage.size), false, UIScreen.main.scale) self.captureView.layer.render(in: UIGraphicsGetCurrentContext()!) self.photoToShare = UIGraphicsGetImageFromCurrentImageContext() print(self.photoToShare.size) //the size is right UIGraphicsEndImageContext() self.photo.image = self.photoToShare! 问题是什么 ?! 我累了: self.captureView.drawHierarchy(in: self.captureView.bounds , afterScreenUpdates: true) 仍然没有成功 编辑 我尝试了这种方法,抓住然后裁剪,但仍然没有成功 UIGraphicsBeginImageContextWithOptions(self.captureView.bounds.size, false, UIScreen.main.scale) self.captureView.drawHierarchy(in: self.captureView.bounds, afterScreenUpdates: true) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() let cropRect = CGRect(x: 0, y: 0, width: (self.photoImage.size.width) , […]

如何从NSAttributedstring中分离属性并将这些属性应用于其他string?

例如。 就像我们有一个NSAttributedstring一样,我们需要将string和属性分开,然后在其他长度相同的string上使用这些属性。

JSQMessagesViewController自定义链接

我正在使用一个快速的框架 ,我需要能够在消息文本string中有一个像标签。 如果用户发送包含前缀为#的代码的消息,例如:#t3Us9K单个“单词”需要是所有用户可以按下的链接。 请告诉我,如果这是可能的,如果是的话如何做到这一点。

SFSafariViewController作为子视图

我想使用SFSafariViewController,但仍然添加我自己下面的几个button。 我没有find办法做到这一点。 我试过使用 let svc = SFSafariViewController(URL: testURL) self.containerView.addSubview(svc.view) 这导致一个空白的白色屏幕。 有没有办法做到这一点与SFSafariViewController或我必须build立自己的“浏览器”与WKWebView? 提前致谢!