- NSString
- CGRect
- class
- selector
-------------------------------------------------
-
NSString
1.对比扩展名
NSString fileName = @"xx.Gif";
//获取扩展名
NSString extension = fileName.pathExtension;
//将扩展名小写后对比
[extension.lowercaseString isEqualToString:@"gif"];
2.字符串替换
[@"x_x" stringByReplacingOccurrencesOfString:@"_" withString:@""];
3.判断字符串
//判断字符串是否以http字符开始
BOOL hasPrefix = [@"http://zhidao.baidu.com/liuyan/detail?id=6004" hasPrefix:@"http"];
//判断字符串是否以http字符结尾
BOOL hasSuffix = [@"http://zhidao.baidu.com/liuyan/detail?id=6004" hasSuffix:@"http"];
4.字符串画到View
/
* 绘制占位文字(每次drawRect:之前, 会自动清除掉之前绘制的内容)
*/
- (void)drawRect:(CGRect)rect {
// 如果有文字, 直接返回, 不绘制占位文字
if (self.hasText) return;// 文字属性 NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = self.font; attrs[NSForegroundColorAttributeName] = self.placeholderColor; [@"要画的字符串" drawInRect:rect withAttributes:attrs]; }
-------------------------------------------------
- CGRect
1.转换坐标系
//subview.superview的坐标转换成keyWindow的坐标。nil代表[[UIApplication sharedApplication].keyWindow
CGRect newFrame = [subview.superview convertRect:subview.frame toView:nil];
//等价上面
CGRect newFrame1 = [[UIApplication sharedApplication].keyWindow convertRect:subview.frame fromView:subview.superview];
2.frame是否有重叠
CGRectIntersectsRect(frame1, frame2);
-------------------------------------------------
- class
-(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例
-(BOOL) isMemberOfClass: classObj 判断是否是这个类的实例
isKindOfClass来确定一个对象是否是一个类的成员,或者是派生自该类的成员
isMemberOfClass只能确定一个对象是否是当前类的成员
NSLog(@"%d,%d", [[NSMutableData data] isKindOfClass:[NSData class]],[[NSMutableData data] isMemberOfClass:[NSData class]]);
打印:2016-04-03 10:39:03.623 01-xxx[1680:35179] 1,0
------------------------------------------------- - selector
-(BOOL) respondsToSelector: selector 判读实例是否有这样方法
+(BOOL) instancesRespondToSelector: 判断类是否有这个方法。此方法是类方法,不能用在类的对象