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
# 最后進(jìn)入自己的工程,在自己工程的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)替換字符串內(nèi)所有空格的方法:

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

(5)替換字符串內(nèi)所有空格的方法:

NSString *str = [str stringByReplacingOccurrencesOfString:@"n" withString:@""];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容