此代码在ios10中正常工作。 我得到我的标签和一个图像button,这是用户的照片configuration文件,圆形圆….好吧。 但是当运行xcode 9 ios11模拟器时,我把它拉长了。 button框架必须是32×32,当检查模拟和获取视图,并告诉xcode描述视图我得到的输出为170×32或类似的东西。 inheritance我的代码。 let labelbutton = UIButton( type: .system) labelbutton.addTarget(self, action:#selector(self.toLogin(_:)), for: .touchUpInside) labelbutton.setTitleColor(UIColor.white, for: .normal) labelbutton.contentHorizontalAlignment = .right labelbutton.titleLabel?.font = UIFont.systemFont(ofSize: 18.00) let button = UIButton(type: .custom) button.addTarget(self, action:#selector(self.toLogin(_:)), for: .touchUpInside) button.frame = CGRect(x: 0, y: 0, width: 32, height: 32) button.setTitleColor(UIColor.white, for: .normal) button.setTitleColor(UIColor.white, for: .highlighted) var buttomItem : […]
我需要使iPhone震动,但我不知道如何在Swift中做到这一点。 我知道在Objective-C中,你只需写: import AudioToolbox AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); 但是这不适合我。
当我尝试过如何使用swift设置可以input到UITextField的最大字符数? ,我看到如果我使用全部10个字符,我也不能抹去字符。 我唯一能做的就是取消操作(一起删除所有的字符)。 有谁知道如何不阻止键盘(以便我不能添加其他字母/符号/数字,但我可以使用退格键)?
我正在通过苹果开发者页面的iOS教程。 在我看来, protocol和interface几乎具有相同的function。 两者有什么分别吗? 项目中的不同用法? 更新 是的 ,我没有阅读上面的链接,我仍然不确定protocol和interface之间的差异和用法。 当我问这样的问题时,我想看一个关于这个话题的简单解释。 有时从文档中获取所有内容可能很困难。
我在一个类中有这个函数: func multiply(factor1:Int, factor2:Int) -> Int{ return factor1 * factor2 } 我尝试使用这个函数调用函数: var multResult = calculator.multiply(9834, 2321) 问题是编译器希望它看起来更像这样: var multResult = calculator.multiply(9834, factor2: 2321) 为什么第一个导致错误?
我向用户展示一个UIAlertView ,我不知道如何编写处理程序。 这是我的尝试: let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default, handler: {self in println("Foo")}) 我在Xcode中遇到了一堆问题。 文档中提到了convenience init(title title: String!, style style: UIAlertActionStyle, handler handler: ((UIAlertAction!) -> Void)!) 现在,整个街区/封闭物都比我头高一点。 任何build议都非常感谢。
我试图导入各种图书馆,我不记得他们的确切名称。 不幸的是XCode 6(使用swift )并不像使用objective-c在XCode 5中那样自动完成它们。 例如: ALAssetsLibrary MPMediaPlayer 等等 我被迫谷歌确切的框架名称,然后回去复制粘贴。 一般来说,自动完成function非常糟糕。 我在XCode 6中做错了什么? 我应该在设置中设置任何标志来使其工作?
在包含Objective-C和Swift代码的自定义框架中,Swift编译器会引发以下错误: [build_path]/unextended-module.modulemap:2:19: error: umbrella header 'bugtest.h' not found umbrella header "bugtest.h" ^ <unknown>:0: error: could not build Objective-C module 'bugtest'
在swift中没有main()方法。 程序必须从某处开始执行。 那么swift代码执行的入口是什么?它是如何决定的?
我有一个定义结构的swift框架: public struct CollectionTO { var index: Order var title: String var description: String } 但是,我似乎无法使用从导入库的另一个项目隐式成员明智的初始值设定项。 错误是'CollectionTO'无法初始化,因为它没有可访问的初始化程序。 即它没有给默认隐式成员明智的初始化公开关键字。 var collection1 = CollectionTO(index: 1, title: "New Releases", description: "All the new releases") 我不得不添加我自己的init方法,如下所示: public struct CollectionTO { var index: Order var title: String var description: String public init(index: Order, title: String, description: String) { self.index = […]