準(zhǔn)確判斷一個(gè)字符串是否有內(nèi)容
if (string.length) {
}
/*
錯(cuò)誤寫法:
if (string) {
}
*/
查找字符串的常見方法
// 如果range.location == 0, 說(shuō)明是以searchString開頭
// 如果range.location == NSNotFound或者range.length == 0, 說(shuō)明沒找到對(duì)應(yīng)的字符串
- (NSRange)rangeOfString:(NSString *)searchString;
// 是否以str開頭
- (BOOL)hasPrefix:(NSString *)str;
// 是否以str結(jié)尾
- (BOOL)hasSuffix:(NSString *)str;
// 是否包含了str(不管頭部\中間\尾部)
- (BOOL)containsString:(NSString *)str;
計(jì)算文字的寬度
CGFloat titleW = [字符串 sizeWithFont:字體大小].width;
CGFloat titleW = [字符串 sizeWithAttributes:@{NSFontAttributeName : 字體大小}].width;
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者