【Swift】iOS开发历险记(一)
1、隐藏/显示密码功能
光设置secureTextEntry还不行,你会发现UITextField在切换到显示密码时会多一个空字符,看着巨别扭,需要在更改secureTextEntry后进行如下设置:
let pwd = psdField.textself.psdField.text = pwd + " "
self.psdField.text = pwd
2、获取当前类的名称
String.fromCString(object_getClassName(self))注意:通过_stdlib_getDemangledTypeName也能取到,但是如果在父类里面去就只能取到父类的名称
3、 国际化
find . \( -name *.m -o -name *.h \) -print0 | xargs -0 genstrings -o en.lproj
凡是使用了NSLocalizedString的字符串都能被找到,支持子目录查找,注意替换en.lproj
4、UITableView分割线的显示问题
去掉分割线:设置UITableView的separatorStyle = UITableViewCellSeparatorStyle.None
去掉多余的分割线:设置UITableView的tableFooterView = UIView() (要是不设置会很丑,不管有没有数据都会显示分割线)
处理 iOS8 分割线左边距设置为0失效的问题,参考这里(http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working):
![复制代码](http://common.cnblogs.com/images/copycode.gif)
// Remove seperator inset
if cell.respondsToSelector("setSeparatorInset:") {
cell.separatorInset = UIEdgeInsetsZero
}
// Prevent the cell from inheriting the Table Views margin settings
if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") {
cell.preservesSuperviewLayoutMargins = false
}
// Explictly set your cells layout margins
if cell.respondsToSelector("setLayoutMargins:") {
cell.layoutMargins = UIEdgeInsetsZero
}
}
![复制代码](http://common.cnblogs.com/images/copycode.gif)
5、 格式化数字输出 K/M
![复制代码](http://common.cnblogs.com/images/copycode.gif)
public func substring(startIndex: Int, endIndex: Int) - String{
return (self as NSString).substringWithRange(NSRange(location: startIndex, length: endIndex - startIndex))
}
}
public static func prettyNumber(num: Double) - String{
if (num 10000) {
return "\(Int(num))";
} else if (num 100000) {
return "\(num / 1000.0)".substring(0, endIndex: 4) + "K"
} else if (num 1000000) {
return "\(num / 1000.0)".substring(0, endIndex: 3) + "K"
} else if (num 100000000) {
return "\(num / 1000000.0)".substring(0, endIndex: 4) + "M"
} else if (num 1000000000) {
return "\(num / 1000000.0)".substring(0, endIndex: 3) + "M"
} else if (num 100000000000) {
return "\(num / 1000000000.0)".substring(0, endIndex: 4) + "M"
} else if (num 1000000000000) {
return "\(num / 1000000000.0)".substring(0, endIndex: 3) + "M"
}
return "INF";
}
![复制代码](http://common.cnblogs.com/images/copycode.gif)
6、 判断屏幕是否是横屏
public static func isIsLandscape() - Bool { return UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation) || UIApplication.sharedApplication().statusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.sharedApplication().statusBarOrientation == UIInterfaceOrientation.LandscapeRight }
7、 URL 编码
text.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
这个 text 的类型是 String ,常用于搜索功能,在 URL 中包含被搜的关键字,如果不处理搜中文或者带空格的英文会直接崩溃
转载:http://www.cnblogs.com/over140/p/4571398.html
iOS 仿支付宝银行卡界面(支持Swift/OC) 在有支付相关的APP中,都有对应的钱包,虽然现在的支付宝,微信支付很流行,但是都是需要绑定自己的银行卡,那么这个银行卡的卡包页面该怎么实现呢?在网上找了许久也没有找到合适的,那就索性自己造轮子。
相关文章
- IOS屏幕录制应用xRec上架App store
- iOS小技能:设置状态栏背景颜色(图片)
- 【IOS实用玩机技巧】爱思助手 IPA 签名功能常见问题汇总
- iOS开发应用上传AppStore的步骤
- 理解iOS端的WebView同层组件
- use SceneKit to display 3d objects in an iOS project
- 【iOS 开发】iOS 开发 简介 (IOS项目文件 | MVC 模式 | 事件响应机制 | Storyboard 控制界面 | 代码控制界面 | Retina 屏幕图片适配)
- 理解 iOS 的内存管理详解手机开发
- iOS 应用开发中的断点续传实践总结详解手机开发
- iOS检测耳机是否插入详解手机开发
- iOS获取汉字首字母详解手机开发
- iOS 8 实现获取当前定位信息详解手机开发
- iOS异步请求下载图片详解手机开发
- iOS图片处理,截图,缩放,存储详解手机开发
- IOS校验验证手机号,信用卡号,电话号码,邮编,Email等详解手机开发
- iOS网络操作与AFNetworking详解手机开发
- ios 获取网络类型详解手机开发
- iOS实现旋转详解手机开发
- IOS 雪花飘落效果详解手机开发
- iOS通过http post上传图片详解手机开发
- iOS-蓝牙学习资源博文收集详解手机开发
- iOS-绘制UIView之drawCGRect详解手机开发
- iOS—SQLite数据库框架之FMDB -Swift详解手机开发
- iOS开发——高级技术&蓝牙服务详解手机开发
- 深入理解iOS图文混排原理并自定义图文控件