Tag: swift

无法将typesNSAttributedString.DocumentAttributeKey的值转换为.DocumentReadingOptionKey

我在互联网上的某个地方发现了这个string扩展,它允许我把html代码转换成属性string: func html2AttributedString() -> NSAttributedString { return try! NSAttributedString(data: self.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) } 它在Swift 3中运行良好,但是在Swift 4中,Xcode抱怨: 无法将types“NSAttributedString.DocumentAttributeKey”的值转换为期望的字典键types“NSAttributedString.DocumentReadingOptionKey” 我该如何解决?

截图显示空白 – 斯威夫特

嗨,我正在做一个游戏,我已经添加了一个分享button的游戏。 我希望用户能够在一条消息中共享消息,URL和屏幕截图。共享方面工作正常,除了屏幕截图本身显示空白以外,所有内容都显示出来。 这是我用来截图的代码: let layer = UIApplication.sharedApplication().keyWindow!.layer let scale = UIScreen.mainScreen().scale UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale); layer.renderInContext(UIGraphicsGetCurrentContext()) let screenshot = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil) println("screenshot") 请帮我解决这个问题,请确保在Swift语言中这样做。 此外,我使用SpriteKit技术,如果这有所作为。 我是新来的编码,所以请非常清楚。 非常感谢你!

(Swift)如何在string中打印“\”字符?

我试图打印它,但它只是通过,因为它是一个逃脱的字符。 例如输出应该如下。 \correct 提前致谢

为什么主窗口的types是double可选的?

当访问UIapplication's主窗口时,它将作为UIWindow??返回UIWindow?? let view = UIApplication.sharedApplication().delegate?.window // view:UIWindow?? 为什么它返回作为一个双选项,它是什么意思,如果放入一个if let我应该加一个! 之后呢? if let view = UIApplication.sharedApplication().delegate?.window! 我的第一个虽然是取代? 用! 委托后,但这不是解决scheme。

将UITabBar定位在顶部

我是iOS开发的初学者。 我的问题是:是否有可能将UITabBar定位在顶端? 我无法将我的UITabBar放在视图的顶部。

在Swift中的有序字典

有什么内置的方式来创build一个有序的地图在Swift 2? 数组[T]按照对象附加到它的顺序sorting,但字典[K : V]不是有序的。 例如 var myArray: [String] = [] myArray.append("val1") myArray.append("val2") myArray.append("val3") //will always print "val1, val2, val3" print(myArray) var myDictionary: [String : String] = [:] myDictionary["key1"] = "val1" myDictionary["key2"] = "val2" myDictionary["key3"] = "val3" //Will print "[key1: val1, key3: val3, key2: val2]" //instead of "[key1: val1, key2: val2, key3: val3]" print(myDictionary) 有没有什么内置的方法来创build一个有序的key […]

AlertController不在窗口层次结构中

我刚刚创build了一个ViewController类的单一视图应用程序项目。 我想从位于我自己的类中的函数显示一个UIAlertController。 这是我的class级警报。 class AlertController: UIViewController { func showAlert() { var alert = UIAlertController(title: "abc", message: "def", preferredStyle: .Alert) self.presentViewController(alert, animated: true, completion: nil) } } 这是执行警报的ViewController。 class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } @IBAction func showAlertButton(sender: AnyObject) { var alert = AlertController() alert.showAlert() } } 这是我得到的,而不是美丽的戒备。 警告:尝试在Sprint1.AlertController上显示UIAlertController:0x797d2d20:0x797cc500其视图不在窗口层次结构中! 我该怎么办?

IOS 8选项卡栏项目背景颜色

上周我一直在努力寻找解决scheme,在尝试find或想到的所有可能的解决scheme之后,我一直没有运气。 我发现和尝试的每个解决scheme都没有工作,或者已经过时。 我有UITabBar放在UITabBarController内的UITabBarController 。 我想在select时更改UITabBarItem的背景颜色,当然当select的项目发生变化时它会变回。 我在Xcode 6.3.1中使用Swift和iOS SDK 8.3。 如果你只能在Objective-C中回答这个问题,那么任何答案都会有帮助! 谢谢大家,我真的很感激! 编辑:这是我想要它做的一个视觉例子。 不同的背景颜色

iOS中的链接器错误(体系结构x86_64的重复符号)

我继续得到以下错误: duplicate symbol _llvm.embedded.module in: /Users/name/Documents/FacebookSDKs-iOS-20150910/FBSDKCoreKit.framework/FBSDKCoreKit(FBSDKApplicationDelegate.o) /Users/name/Documents/FacebookSDKs-iOS-20150910/FBSDKCoreKit.framework/FBSDKCoreKit(FBSDKServerConfiguration.o) ld: 102 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 我已经尝试删除FBSDK并重新安装,但没有工作。 我也怀疑,我将这个框架连接到Swift可能是个问题。 我的桥接头包含以下内容: #ifndef EggCrush_Bridge_h #define EggCrush_Bridge_h #import <FBSDKCoreKit/FBSDKCoreKit.h> #endif 我的AppDelegate.swift文件导入FBSDKCoreKit。 没有其他链接器标志。 我正在运行Xcode 6.3.2并为iOS 8.3构build一个项目 如何清除这个错误?

如何在Swift中设置UIButton背景色forState:UIControlState.Highlighted

我可以设置一个button的背景颜色,但我不知道如何设置UIControlState.Highlighted的背景颜色。 这甚至有可能吗? 或者我需要沿着setBackgroundImagepath?