一、去掉tableviewcell
的左边多余的15像素
- 1.可以改变
tableviewcell
的样式为
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
然后在自定义的cell下面加上一个UIview
在底部,设置UIview
的颜色为分割线的样式即可 - 2.同样设置
tableviewcell
的样式为
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
在自定义的cell中重写下面这个方法,然后设置self.tableView.backgroundColor = CommonBgColor;
这样就分割线的颜色就会显示为和tableview的背景颜色一致了
/**
* 重写这个方法的目的: 能够拦截所有设置cell frame的操作
*/
- (void)setFrame:(CGRect)frame
{
// 这里可以自定义cell分割线的样式
CGFloat margin= 1;
frame.size.height -= margin;
frame.origin.y += margin;
[super setFrame:frame];
}
- 3.首先在viewDidLoad方法加入以下代码:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在重写willDisplayCell方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
即可实现分割线的长度 = 屏幕的宽度
二、调节Label的行间距
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.contentLabel.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:3];
//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.contentLabel.text length])];
self.contentLabel.attributedText = attributedString;
三、iOS 开发中一些相关的路径
- 1.模拟器的位置:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
- 2.文档安装位置:
/Applications/Xcode.app/Contents/Developer/Documentation/DocSets
- 3.插件保存路径:
~/Library/ApplicationSupport/Developer/Shared/Xcode/Plug-ins
- 4.自定义代码段的保存路径:(如果找不到CodeSnippets文件夹,可以自己新建一个CodeSnippets文件夹)
~/Library/Developer/Xcode/UserData/CodeSnippets/
- 5.证书路径
~/Library/MobileDevice/Provisioning Profiles
四、获取 iOS 路径的方法
- 获取家目录路径的函数
NSString *homeDir = NSHomeDirectory();
- 获取Documents目录路径的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
- 获取tmp目录路径的方法
NSString *tmpDir = NSTemporaryDirectory();
五、字符串相关操作
- 去除所有的空格
[str stringByReplacingOccurrencesOfString:@" " withString:@""]
- 去除首尾的空格
[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- 全部字符转为大写字母
- (NSString *)uppercaseString;
- 全部字符转为小写字母
- (NSString *)lowercaseString
六、NULL – nil – Nil – NSNULL的区别
- nil是OC的,空对象,地址指向空(0)的对象。对象的字面零值
- Nil是Objective-C类的字面零值
- NULL是C的,空地址,地址的数值是0,是个长整数
- NSNull用于解决向NSArray和NSDictionary等集合中添加空值的问题
网友评论