1.輸出%
如圖,想要直接輸出%號(hào)是不行的箫攀,需要%%咏闪。
[NSString stringWithFormat:@"16.58%%"];
2.pod 更新報(bào)錯(cuò)
[!] 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'
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 從右往左布局(也可通過(guò)xib改變)
self.collectionView.semanticContentAttribute =UISemanticContentAttributeForceRightToLeft;
這個(gè)屬性的主要目的強(qiáng)制改變布局方向侈咕,在適配阿拉伯語(yǔ)言的時(shí)候可以使用(不只是針對(duì)UICollectionView弧可,其他view都行)捷泞。
5.pods master
新版的 CocoaPods 不允許用pod repo add直接添加master庫(kù)了秉氧,但是依然可以:
$ 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:@""];