iOS 知识点

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'

6.字符串空格换行处理

(1)去掉字符串首尾空格的方法:

NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

(2)去掉字符串首尾换行的方法:

NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];

(3)去掉字符串首尾空格和换行的方法:

NSString *str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

(4)替换字符串内所有空格的方法:

NSString *str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];

(5)替换字符串内所有空格的方法:

NSString *str = [str stringByReplacingOccurrencesOfString:@"n" withString:@""];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容