工作生活

iOS 知识点

2019-07-03  本文已影响0人  AmumuHandsome

1.输出%

image.png
  如图,想要直接输出%号是不行的,需要%%。
  [NSString stringWithFormat:@"16.58%%"];

2.pod 更新报错

[!] CDN: trunk URL couldn't be downloaded: https://cdn.cocoapods.org/all_pods_versions_a_7_5.txt, error: execution expired

需要再podfile里面加上
source 'https://github.com/CocoaPods/Specs.git'
image.png

3.富文本图文拼接

//图片文本拼接
- (UIImage *)imageWithText:(NSString *)text
                  textFont:(NSInteger)fontSize
                 textColor:(UIColor *)textColor
                 textFrame:(CGRect)textFrame
               originImage:(UIImage *)image
    imageLocationViewFrame:(CGRect)viewFrame {
    
    if (!text)      {  return image;   }
    if (!fontSize)  {  fontSize = 17;   }
    if (!textColor) {  textColor = [UIColor blackColor];   }
    if (!image)     {  return nil;  }
    if (viewFrame.size.height==0 || viewFrame.size.width==0 || textFrame.size.width==0 || textFrame.size.height==0 ){return nil;}
 
    NSString *mark = text;
    UIGraphicsBeginImageContext(viewFrame.size);
    [image drawInRect:CGRectMake(0, 0, viewFrame.size.width, viewFrame.size.height)];
    NSDictionary *attr = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:fontSize], NSForegroundColorAttributeName : textColor };
    //位置显示
    [mark drawInRect:CGRectMake(textFrame.origin.x, textFrame.origin.y, textFrame.size.width, viewFrame.size.height) withAttributes:attr];
    
    UIImage *aimg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return aimg;

}

4.UICollectionView 从右往左布局(也可通过xib改变)

    self.collectionView.semanticContentAttribute =UISemanticContentAttributeForceRightToLeft;

这个属性的主要目的强制改变布局方向,在适配阿拉伯语言的时候可以使用(不只是针对UICollectionView,其他view都行)。

5.pods master

新版的 CocoaPods 不允许用pod repo add直接添加master库了,但是依然可以:
$ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
# 最后进入自己的工程,在自己工程的podFile第一行加上:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
上一篇下一篇

猜你喜欢

热点阅读