美文网首页
iOS 的一点小记载(二)

iOS 的一点小记载(二)

作者: lonelyjimmy | 来源:发表于2017-05-25 08:58 被阅读8次

控制台可能会输出以下警告信息

  • 警告的原因: [UIImage imageNamed:nil]
CUICatalog: Invalid asset name supplied: (null)
CUICatalog: Invalid asset name supplied: (null)
  • 警告的原因: [UIImage imageNamed:@""]
CUICatalog: Invalid asset name supplied:
CUICatalog: Invalid asset name supplied:

准确判断一个字符串是否有内容

if (string.length) {

}

/*
错误写法:
if (string) {

}
*/

替换UITabBarController内部的tabBar

// 这里的self是UITabBarController
[self setValue:[[XMGTabBar alloc] init] forKeyPath:@"tabBar"];

center和size的设置顺序

  • 建议的设置顺序
    • 先设置size
    • 再设置center

给系统自带的类增加分类

  • 建议增加的分类属性名\方法名前面加上前缀, 比如
@interface UIView (CLExtension)
@property (nonatomic, assign) CGFloat cl_width;
@property (nonatomic, assign) CGFloat cl_height;
@property (nonatomic, assign) CGFloat cl_x;
@property (nonatomic, assign) CGFloat cl_y;
@property (nonatomic, assign) CGFloat cl_centerX;
@property (nonatomic, assign) CGFloat cl_centerY;

@property (nonatomic, assign) CGFloat cl_right;
@property (nonatomic, assign) CGFloat cl_bottom;
@end

按钮常见的访问方法

[button imageForState:UIControlStateNormal].size;
button.currentImage.size;

[button backgroundImageForState:UIControlStateNormal];
button.currentBackgroundImage;

[button titleForState:UIControlStateNormal];
button.currentTitle;

[button titleColorForState:UIControlStateNormal];
button.currentTitleColor;

设置按钮的内边距

@property(nonatomic) UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR;
@property(nonatomic) UIEdgeInsets titleEdgeInsets;
@property(nonatomic) UIEdgeInsets imageEdgeInsets;

解决导航控制器pop手势失效

self.interactivePopGestureRecognizer.delegate = self;

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 手势何时有效 : 当导航控制器的子控制器个数 > 1就有效
    return self.childViewControllers.count > 1;
}

相关文章

网友评论

      本文标题:iOS 的一点小记载(二)

      本文链接:https://www.haomeiwen.com/subject/bsuaxxtx.html