1、取出UISearchBar中的控件进行属性设置
UITextField *sbTextField = [_searchBar valueForKey:@"searchField"]; //首先取出textfield
UILabel *sbPlaceholderLabel = [sbTextField valueForKey:@"placeholderLabel"]; //然后取出textField的placeHolder
sbPlaceholderLabel.font = [UIFont systemFontOfSize:13];
类似的,按钮之类的控件也可以用KVC进行对私有属性赋值或者更改。
2、关于压缩图片的一些方法
//压缩图片质量
-(UIImage *)reduceImage:(UIImage *)image percent:(float)percent
{
NSData *imageData = UIImageJPEGRepresentation(image, percent);
UIImage *newImage = [UIImage imageWithData:imageData];
return newImage;
}
//压缩图片尺寸
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
//裁剪图片
- (UIImage *)cutImage:(UIImage*)image
{
CGSize newSize;
CGImageRef imageRef = nil;
if (image.size.width < image.size.height) {
newSize = CGSizeMake(image.size.width, image.size.width);
imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(0, fabs(image.size.height - newSize.height) / 2, newSize.width, newSize.height));
} else {
newSize = CGSizeMake(image.size.height, image.size.height);
imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(fabs(image.size.width - newSize.width) / 2, 0, newSize.width, newSize.height));
}
return [UIImage imageWithCGImage:imageRef];
}
3、UITextView去除文字顶部空白的办法
UITextView *textV = [[UITextView alloc] init];
textV.frame = CGRectMake(100, 100, 200, 100);
textV.scrollEnabled = YES;
textV.textContainerInset = UIEdgeInsetsZero;
textV.text = @"看了就收到了房价来说上飞机上连接发垃圾垃圾 案例附件是龙卷风是就 死了快捷方式发送方经理说发加拉飞机离开积分啊两份案例发 法拉盛交付时间放假了时间了福建省死了放假了快速减肥了手机费老师就疯了酸辣粉简单来说就分手就分了就算了附件是数量多客服经理手机费老师就发来的手机费老师的解放了手机垫付涉及到法律是减肥路上的积分";
textV.backgroundColor = [UIColor redColor];
[self.view addSubview:textV];
效果如下图,图一是没有设置的样式,图二是设置了的样式:
图一 图二
网友评论