开发中一些小总结
好久没更新了,本篇记录一下工作中的一些小东西,也许会对大家有所帮助。
一、UIAlertController
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否支付完成?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *OK = [UIAlertAction actionWithTitle:@"已支付" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//处理操作
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"未支付"style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//处理操作
}];
[alert addAction:OK];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
UIAlertController的提示操作栏,可以自己封装,自定义一下。
二、#000000转换为UIColor
+ (UIColor *) stringTOColor:(NSString *)str { if (!str || [str isEqualToString:@""]) { return nil; } unsigned red,green,blue; NSRange range; range.length = 2; range.location = 1; [[NSScanner scannerWithString:[str substringWithRange:range]] scanHexInt:&red]; range.location = 3; [[NSScanner scannerWithString:[str substringWithRange:range]] scanHexInt:&green]; range.location = 5; [[NSScanner scannerWithString:[str substringWithRange:range]] scanHexInt:&blue]; UIColor *color= [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:1]; return color; }
话不多说,有需求的可以自己添加到自己的工具类里面。
三、NSString部分字符的颜色改变
NSString *moneyStr = [NSString stringWithFormat:@"总价¥%@",_model.bill.billMoney]; NSDictionary *dic = @{ NSKernAttributeName:@0.6f}; NSMutableAttributedString *moneyStr1 = [[NSMutableAttributedString alloc] initWithString:moneyStr attributes:dic]; [moneyStr1 addAttribute:NSForegroundColorAttributeName value:[stringTOColor stringTOColor:@"#000000"] range:NSMakeRange(0,2)]; _money.attributedText = moneyStr1;
dic字典里可以添加其他你想改变的属性,字体、字号啥的,自行百度喽。
效果:
四、tableview的分界线左端到顶
效果是这样的:
//首先需要在viewDidLoad里加入: if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsZero]; } //其次需要实现代理方法 - (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]; } }
持续更新。。。