label的高度确定 计算label所占的宽度
CGRect temp = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, 21) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15.0]} context:nil];
NSLog(@"宽度 : %f",temp.size.width);
图片按比例缩放
UIImageView *imgView = [[UIImageView alloc] init];
imgView.image = [UIImage imageNamed:@"流程图1.png"];
CGFloat scale = imgView.image.size.width / (SCREENW / 2);
CGFloat imgViewHeight = imgView.image.size.height / scale;
imgView.frame = CGRectMake(0, 0, SCREENW / 2, imgViewHeight);
imgView.image = [UIImage imageWithCGImage:imgView.image.CGImage scale:scale orientation:UIImageOrientationUp];
通过颜色制作图片 我是用在导航栏上了
/// 通过颜色制作图片
- (UIImage *)imageWithFrame:(CGRect)frame color:(UIColor *)color alphe:(CGFloat)alphe {
frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
UIColor *redColor = color;
UIGraphicsBeginImageContext(frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAlpha(context, alphe);
CGContextSetFillColorWithColor(context, [redColor CGColor]);
CGContextFillRect(context, frame);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
按钮的图片和文字位置的调整 图片在上 文字在下
-(void)initWithButton:(UIButton*)btn
{
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
[btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.height + 10,-btn.imageView.width, 0.0,0.0)];
[btn setImageEdgeInsets:UIEdgeInsetsMake(-btn.titleLabel.height - 10, 0.0,0.0, -btn.titleLabel.bounds.size.width)];
}
网友评论