1 cell
---由点击cell上的button获取indexPath.row
UITableViewCell * cell = (UITableViewCell*)button.superview;
NSIndexPath * indexPath = [myTableView indexPathForCell:cell];
NSLog(@">>>>>>>>>>>>>>>>>>%ld",indexPath.row);
----由indexPath获取cell
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
UITableViewCell * cell = [myTableView cellForRowAtIndexPath:indexPath];
---把cell默认位置设为选中状态
NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:indexRow inSection:0];
[selTypeTableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
2 设置字体颜色
NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc] initWithString:infoLab.text];
[attributedString1 addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(5, infoLab.text.length-5)]; // 0为起始位置 length是从起始位置开始 设置指定颜色的长度
infoLab.attributedText = attributedString1;
3 格式化时间
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSString * selDateStr = [formatter stringFromDate:pickerView.date];
4 相对frame
CGRect frame=[self.view convertRect:button.frame fromView:button.superview];
CGRect frame=[self.view convertRect:button.frame toView:button.superview];
5 图片设置
<1>设置图片为圆形
[userImgView.layer setCornerRadius:CGRectGetHeight([userImgView bounds])/2];
userImgView.layer.masksToBounds = YES;
<2>按钮圆角
[okBt.layer setCornerRadius:3];
okBt.layer.masksToBounds = YES;
<3>设置图片显示picImgView.contentMode=UIViewContentModeScaleAspectFill;
picImgView.clipsToBounds = YES;
6 取消按钮点击时高亮状态
bt.adjustsImageWhenHighlighted = NO;
7 倒计时
(void)viewDidload{
UILabel * timeLabel;
UIButton * sendCodeBt;
NSTimer * timer;
int timeint;
sendCodeBt = [[UIButton alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
[sendCodeBt.layer setCornerRadius:5];
sendCodeBt.backgroundColor = [UIColor orangeColor];
sendCodeBt.titleLabel.font = [UIFont systemFontOfSize:[FontSizeAutomatic initFontWith5sSize:14]];
[sendCodeBt setTitle:@"发送验证码" forState:UIControlStateNormal];
[sendCodeBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[sendCodeBt addTarget:self action:@selector(sendCodeClick) forControlEvents:UIControlEventTouchUpInside];
[bgView addSubview:sendCodeBt];
timeLabel = [[UILabel alloc] init];
timeLabel.frame = sendCodeBt.frame;
timeLabel.backgroundColor = sendCodeBt.backgroundColor;
timeLabel.layer.cornerRadius = sendCodeBt.layer.cornerRadius;
timeLabel.layer.masksToBounds = YES;
[timeLabel.layer setCornerRadius:5];
timeLabel.font = [UIFont systemFontOfSize:[FontSizeAutomatic initFontWith5sSize:12]];
timeLabel.textAlignment = NSTextAlignmentCenter;
timeLabel.textColor = [UIColor whiteColor];
[bgView addSubview:timeLabel];
timeLabel.hidden = YES;
}
- (void)sendCodeClick{
timeint = 60;
[NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:NO];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
}
//倒计时方法
- (void)timerFireMethod:(NSTimer*)theTimer
{
timeLabel.hidden=NO;
sendCodeBt.hidden=YES;
timeLabel.text = [NSString stringWithFormat:@"%d秒后重新发送",timeint];
timeint = timeint - 1;
if (timeint == -1) {
[timer invalidate];
timeLabel.hidden=YES;
sendCodeBt.hidden=NO;
timer = nil;
}
}
8 打电话
- (void)callPhoneAction{
NSString * phoneNumStr = @“12345678900”;
UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"拨打电话" message:[NSString stringWithFormat:@"拨打:%@",phoneNumStr] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString * phoneStr = [NSString stringWithFormat:@"tel:%@",phoneNumStr];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr]];
}];
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertC addAction:okAction];
[alertC addAction:cancelAction];
[self presentViewController:alertC animated:YES completion:nil];
}