iOS-OC tips

UIButton文字和图标间距:

[button setImageEdgeInsets:UIEdgeInsetsMake(0.0, -20, 0.0, 0.0)];


UITabbarItem的图标大小改变:

vc.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);


UISearchBar设置取消按钮的文字:

[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]].title = @"取消";


自定义Tabbarcontroller:


- (void)setup {

self.tabBar.tintColor = [UIColor initWith:Color_Hex_Main];

self.tabBar.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.96];

self.tabBar.translucent = NO;

[self addChildVC:[HomePageVC class] withTitle:@"首页" withIconName:ImgName_home];

[self addChildVC:[CategoryPageVC class] withTitle:@"分类" withIconName:ImgName_sort];

[self addChildVC:[GrouppurchasePageVC class] withTitle:@"团购" withIconName:ImgName_Group_purchase];

[self addChildVC:[CartPageVC class] withTitle:@"购物车" withIconName:ImgName_shopping_cart];

[self addChildVC:[MinePageVC class] withTitle:@"我的" withIconName:ImgName_my];

}

- (void)addChildVC:(Class )str withTitle:(NSString *)title withIconName:(NSString *)iconName {

UIViewController *vc = [[str alloc]init];

BaseNavVC *nav = [[BaseNavVC alloc]initWithRootViewController:vc];

if ([title isEqualToString:@"团购"]) {

vc.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

}else{

vc.title = title;

}

vc.tabBarItem.image = [UIImage imageNamed:iconName];

vc.tabBarItem.image = [UIImage imageNamed:[iconName stringByAppendingString:@"_d"]];

nav.navigationBar.barTintColor = [UIColor initWith:Color_Hex_Main];

nav.navigationBar.backgroundColor = [UIColor initWith:Color_Hex_Main];

[self addChildViewController:nav];

}



UITabbarItem显示图标本身颜色:

vc.tabBarItem.image = [[UIImage imageNamed:iconName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

vc.tabBarItem.selectedImage = [[UIImage imageNamed:[iconName stringByAppendingString:@"_d"]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];


UITableViewCell仅仅更新视图布局:

//仅仅更新视图高度、这两个方法会让所有的cell重新布局,然后重新计算高度。

[tableView beginUpdates];

[tableView endUpdates];

UITableViewCell selectedBackgroundView修改位置:

重载:

- (void )layoutSubviews {

// always try to set frame in layoutSubviews

[super layoutSubviews];

//    CGRect frame = CGRectMake(52.0, 0, self.width-67.0, self.height);

CGRect frame = CGRectMake(self.contentView.originX+15.0, 0, self.contentView.width-30.0, self.height);

UIView *backView = [[UIView alloc] initWithFrame:frame];

[backView addCommonShadow:4.0];

[backView addLine: self.contentView.width-30.0 distance:38 isDistanceTop:NO];

self.selectedBackgroundView = backView;

self.selectedBackgroundView.backgroundColor = [UIColor whiteColor];

}


UITableViewCell  选择图标修改:

- (void)layoutSubviews

{

[super layoutSubviews];

for (UIControl *control in self.subviews) {

if (![control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){

continue;

}

[control mas_makeConstraints:^(MASConstraintMaker *make) {

make.centerY.equalTo(self);

make.right.mas_offset(-30.0);

}];

for (UIView *subView in control.subviews) {

if (![subView isKindOfClass: [UIImageView class]]) {

continue;

}

UIImageView *imageView = (UIImageView *)subView;

if (self.selected) {

// KVC修改

//修改选中背景图片等

} else {

//修改非选中背景图片等

}}}

iOS 应用跳转到设置界面:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

if ([[UIApplication sharedApplication] canOpenURL:url]) {

[[UIApplication sharedApplication] openURL:url];

}

疑问:

GCC 有个visibility属性, 该属性是说, 启用这个属性:

1. 当-fvisibility=hidden时

动态库中的函数默认是被隐藏的即 hidden. 除非显示声明为__attribute__((visibility("default"))).

2. 当-fvisibility=default时

动态库中的函数默认是可见的.除非显示声明为__attribute__((visibility("hidden"))).

特别说明: 这个特性是 GCC4.0 以后才有的.

NSMutableArray便利构造器

NSMutableArray *marr=[NSMutableArrayarrayWithCapacity:5];

带有capacity的方法,

其内存原理如下:

capacity后的NSUInteger代表了开辟内存的一个单位

初始在内存中开辟5个内存,如果之后数组元素多余5个,则会再开辟新的5*2个新的内存,[考虑到数组的连续内存的特性]

单位是以5,把之前的5个元素的内容拷贝到新的十个新的内存里面,把第六个

也放进去,然后释放初始状态创建的内存5个

最后得到了一块够用的连续的内存5*2

如果创建的framework中使用了category类,则在使用framework的项目配置中【Other Linker Flags】需要添加参数【-ObjC]或者【-all_load】。

如果使用framework的使用出现【Umbrella header for module 'XXXX' does not include header 'XXXXX.h'】,是因为错把xxxxx.h拖到了public中。

如果出现【dyld: Library not loaded:XXXXXX】,是因为打包的framework版本太高。比如打包framework时,选择的是iOS 9.0,而实际的工程环境是iOS 8开始的。

指令集对应的设备

armv6

iPhone、iPhone 3G

iPod 1G、iPod 2G

armv7

iPhone 3GS、iPhone 4

iPod 3G、iPod 4G、iPod 5G

iPad、iPad 2、iPad 3、iPad Mini

armv7s

iPhone 5、iPhone 5C

iPad 4

arm64

iPhone 5s iPhone 6iPhone 6P iPhone 6s iPhone 6sP iPhone 7 iPhone 7P

iPad Air, Retina iPad Mini

判断当前设备是否为iPhone X

#define KIsiPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

你可能感兴趣的:(iOS-OC tips)