摘要: iOS对于摇一摇功能封装比较好,只需要简单三部就能实现该功能。1. 在```viewDidLoad```中添加代码```UIApplication.shared.applicationSupportsShakeToEdit = true``` ,启动摇一摇功能2. 重写```canBecomeFirstResponder```返回true,使控制器能响应摇一摇事件3. 根据需要重写```motio... 阅读全文
posted @ 2017-02-10 12:28 oceannw 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 对需要转换的Data对象选择nonLossyASCII界面就行,参考代码如下:````swiftNSString(data: result, encoding: String.Encoding.nonLossyASCII.rawValue)```` 阅读全文
posted @ 2017-02-10 12:28 oceannw 阅读(273) 评论(0) 推荐(0) 编辑
摘要: UIScrollView最简单的设置初始化滚动位置的方法是重写layoutSubviews,并实现目标效果,参考代码如下:```swift override func layoutSubviews() { super.layoutSubviews() scrollView.contentOffset = CGPointMake(0, 0) }``` 阅读全文
posted @ 2017-02-10 12:27 oceannw 阅读(937) 评论(0) 推荐(0) 编辑
摘要: 由于Self具有运行时动态特性,实现protocol必须禁止类的继承,否则,由于类型确定导致编译器不通过,具体详见如下例子:```swiftprotocol AProtocol{ func createViewController() -> Self?}final class BClass:AProtocol{ func createViewController() -> BClass... 阅读全文
posted @ 2017-02-10 12:27 oceannw 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 实现该功能非常简单,只需要导入```AudioToolbox.framework```包,然后再需要使用的地方调用以下代码即可。```swiftAudioServicesPlaySystemSound(kSystemSoundID_Vibrate)``` 阅读全文
posted @ 2017-02-10 12:27 oceannw 阅读(125) 评论(0) 推荐(0) 编辑
摘要: ```swiftlet systemFont = UIFont.systemFontOfSize(14)let otherFont = UIFont(descriptor: systemFont.fontDescriptor(), size: 16)```以下是错误形式:```swiftlet systemFont = UIFont.systemFontOfSize(14)let otherFon... 阅读全文
posted @ 2017-02-10 12:26 oceannw 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 在Storyboard中要设置UILabel的两边对齐会出现无效果的情况,需要通过代码来实现,关键操作为NSMutableParagraphStyle的设置,其中必须设置NSUnderlineStyleAttributeName属性,否则没有效果,具体如下: ```swiftlet infoString = NSMutableAttributedString(string:"Test")le... 阅读全文
posted @ 2017-02-10 12:26 oceannw 阅读(535) 评论(0) 推荐(0) 编辑
摘要: 由于iOS9系统使用全新的SF字体作为显示的数字字体,该字体具有比例字体的属性功能,使不同字母和数字的宽度按具体的字体来进行比例调整,对于需要统一字体宽度或者是倒计时等功能的字体显示时,会造成字体长短不一或数字抖动等问题,解决方法有两种:1. StoryBoard设置:把Font的设置从System设置为Helvetica Neue。2. 代码设置,把需要调整的字体按以下方式设置,可调整为等宽字体... 阅读全文
posted @ 2017-02-10 12:24 oceannw 阅读(494) 评论(0) 推荐(0) 编辑