iOS开发小技巧

2019-04-01  本文已影响0人  LWide

.UITableView的plain样式下,取消区头停滞效果

iOS 获取汉字的拼音

//阿拉伯数字转中文格式

图片添加水印
-(UIImage *)aspjpegImage:(UIImage *)img withWord:(NSString )word
{
NSString
mark = word;

int w = img.size.width;

int h = img.size.height;
//UIGraphicsBeginImageContext创建一个基于位图的上下文(context),并将其设置为当前上下文(context)
UIGraphicsBeginImageContext(img.size);

[img drawInRect:CGRectMake(0, 0, w, h)];

NSDictionary *attr = @{
                       
                       NSFontAttributeName: [UIFont boldSystemFontOfSize:20],   //设置字体
                       
                       NSForegroundColorAttributeName : [UIColor redColor]      //设置字体颜色
                       
                       };
//文本绘制 attr代表文本属性
[mark drawInRect:CGRectMake(0, 10, 100, 50) withAttributes:attr];                 //左上角

[mark drawInRect:CGRectMake(w - 200, 10, 200, 50) withAttributes:attr];            //右上角

[mark drawInRect:CGRectMake(w - 200, h - 50 - 10, 200, 50) withAttributes:attr];   //右下角

[mark drawInRect:CGRectMake(0, h - 50 - 10, 200, 50) withAttributes:attr];        //左下角

UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return newImg;

}

取上整与取下整
floor(x),有时候也写做Floor(x),其功能是“下取整”,即取不大于x的最大整数 例如:
x=3.14,floor(x)=3
y=9.99999,floor(y)=9
与floor函数对应的是ceil函数,即上取整函数。

ceil函数的作用是求不小于给定实数的最小整数。
ceil(2)=ceil(1.2)=cei(1.5)=2.00
floor函数与ceil函数的返回值均为double型

给UIView设置图片
UIImage *image = [UIImage imageNamed:@"image"];
self.MYView.layer.contents = (__bridge id _Nullable)(image.CGImage);
self.MYView.layer.contentsRect = CGRectMake(0, 0, 0.5, 0.5);

41.防止scrollView手势覆盖侧滑手势
[scrollView.panGestureRecognizerrequireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];

//字符串中是否含有中文

上一篇 下一篇

猜你喜欢

热点阅读