需求:将字符串:请阅读下面相关内容,进行下一步请点击:同意 ,中"同意"二字设置为红色
NSMutableAttributedString *str=[[NSMutableAttributedString alloc]initWithString:@"请阅读下面相关内容,进行下一步请点击:同意"];//NSRange:要改变的位置 NSRange redRange=NSMakeRange([[str string]rangeOfString:@"同意"].location, [[str string]rangeOfString:@"同意"].length);//value :要改变的颜色 [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange]; [self.label setAttributedText:str];
需求:图片按规格剪切
UIImage *image1=[UIImage imageNamed:@"icon"]; CGRect frame = self.image1.bounds;//注意:这里是按照像素剪切,所以要在width 、height后面乘2 CGImageRef finalImgRef = CGImageCreateWithImageInRect(image1.CGImage, CGRectMake(0, 0, frame.size.width*2, frame.size.height*2));
需求:在每组TV的header位置添加自定义的UIView
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section==0) { UIView *header =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)]; header.backgroundColor=[UIColor redColor]; return header; }else if(section==1){ Header *hview=[[[NSBundle mainBundle]loadNibNamed:@"header" owner:self options:nil]lastObject]; return hview; }else{ return [UIView alloc];}}-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 100;}//二者缺一不可