1.UITextView垂直居中顯示文字猪杭,先設置好布局。因為UITextView集成自UIScrollView基显,所以設置偏移量就可以了
//textView的contentSize屬性
CGSize contentSize = textView.contentSize;
//如果文字內(nèi)容高度沒有超過textView的高度
if(contentSize.height <= textView.frame.size.height) {
//textView的高度減去文字高度除以2就是Y方向的偏移量戚嗅,也就是textView的上內(nèi)邊距
CGFloat offsetY = (textView.frame.size.height - contentSize.height)/2;
UIEdgeInsets offset = UIEdgeInsetsMake(offsetY, 0, 0, 0);
[textView setContentInset:offset];
}
2.判斷是否是網(wǎng)頁的正則
NSString *reg = @"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";
NSPredicate *urlPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", reg];
return [urlPredicate evaluateWithObject:url];
3.判斷字符串是不是NULL
+(BOOL)IsNotEmpty:(id)string
{
BOOL result = NO;
if (![string isKindOfClass:[NSNull class]])
{
if (string != nil)
{
result = YES;
}
}
return result;
}
4.時間戳轉(zhuǎn)時間
+(NSString *)timeConversionWithTimeStamp:(NSString *)timeStamp
{
NSString *latestMessageTime = @"";
double timeInterval = [timeStamp doubleValue];
if(timeInterval > 140000000000) {
timeInterval = timeInterval / 1000;
}
NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
latestMessageTime = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:timeInterval]];
}
5.截圖
/**
* 截圖
*
* @param view 需要截取的視圖
*
* @return 截圖 圖片
*/
+ (UIImage *)screenShotFormView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
6.圖片設置圓角
/**
* 圖片設置圓角
*
* @param cornerRadius 圓角值
* @param image 圖片
*
* @return 圓角圖片
*/
- (UIImage *)imageWithCornerRadius:(CGFloat)cornerRadius image:(UIImage *)image
{
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(image.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:frame
cornerRadius:cornerRadius] addClip];
// 畫圖
[image drawInRect:frame];
// 獲取新的圖片
UIImage *im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return im;
}