彩票2-0617(自定义button文左图右)
-------------------------------------------------
设置状态栏颜色
button拖到 bar button item上 这样可以图文都能设置了
----
自定义button文左图右
(button拖到bar button item里,自动包装button)
重写titleRectForContentRect imageRectForContentRect
// NJTitleButton.m // 09-彩票(lottery) #import "NJTitleButton.h" //#import <Availability.h> @interface NJTitleButton () @property (nonatomic, strong) UIFont *myFont; @end @implementation NJTitleButton - (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self setup]; } return self; } - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setup]; } return self; } - (void)setup { // 记录按钮标题的字体 self.myFont = [UIFont systemFontOfSize:15]; // 设置标题的字体 self.titleLabel.font = self.myFont; // 设置按钮的图片显示的内容默认为剧中(为了不拉伸) self.imageView.contentMode = UIViewContentModeCenter; } // 用于返回按钮上标题的位置, 传入按钮的rect - (CGRect)titleRectForContentRect:(CGRect)contentRect { CGFloat titleX = 0; CGFloat titleY = 0; CGFloat titleH = contentRect.size.height; // 获取当前按钮上的文字 // [self titleForState:UIControlStateNormal]; NSString *title = self.currentTitle; CGSize maxSize = CGSizeMake(MAXFLOAT, MAXFLOAT); NSMutableDictionary *md = [NSMutableDictionary dictionary]; // 死循环的原因是self.titleLabel需要访问titleLabel, 而self.titleLabel又需要调用当前方法获取title的范围, 所有死循环 // md[NSFontAttributeName] = self.titleLabel.font; NSLog(@"%@", self.myFont); md[NSFontAttributeName] = self.myFont; // 计算文字的范围 CGFloat titleW = 0; // 判断是否是xcode5 , 如果是就编译一下代码, 如果不是就不编译 #ifdef __IPHONE_7_0 if (iOS7) { // 是IOS7 CGRect titleRect = [title boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:md context:nil]; titleW = titleRect.size.width; }else { // 非IOS7 CGSize titleSize = [title sizeWithFont:self.myFont]; titleW = titleSize.width; } #else // XCODE4 CGSize titleSize = [title sizeWithFont:self.myFont]; titleW = titleSize.width; #endif return CGRectMake(titleX, titleY, titleW, titleH); } - (CGRect)imageRectForContentRect:(CGRect)contentRect { CGFloat imageY = 0; CGFloat imageH = contentRect.size.height; CGFloat imageW = 16; // 图片的X = 按钮的宽度 - 图片宽度 CGFloat imageX = contentRect.size.width - imageW; return CGRectMake(imageX, imageY, imageW, imageH); } @end
----------------
默认系统向下兼容了 系统的适配判断系统的版本,低系统里没有提供7系统增加的方法 要用别的方法处理问题了 和编译器(xcode4)的适配 因为xcode4没有boundingRectWith方法 编译器的适配是采用#ifdef*** #else*** #endif __IPHONE_7_0这个宏定义定义在编译器(xcode5以后)配备的头文件 <Availability/Availability.h>中 而xcode4中的<Availability>中没有定义宏 __IPHONE_7_0
pch文件里
#define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
--------
deprecated 不推荐使用的方法 但是可以使用
在ios5和7之间可以使用的
如果deployment target为6.0就不会有黄色提醒"推荐使用***来代替"
如果deploymebt target为7.1就会有黄色提醒"推荐使用***来代替"
--------------------------
程序可运行的最低版本要求(代表可以在6.0 6.1 7.1 8.0都可以运行 系统都会向下兼容了)
这里的7.1表示用户的手机系统是ios7.1的系统 所以当然可以运行(可以运行的最低版本要求)
xcode可以拿到的api版本(8.4系统支持的所有代码)
-------
-------
ios6 的界面高度(都不是全屏的 且tabBar Controller navigationController veiw的高度依次变小 ios7的所有高度都是全屏化的)
ios6
导航控制器的view宽高 离上面有一段距离 因为默认勾选了 导致这个v变高了(self.edgesForExtendedLayout = TOP向上拉伸 )
而ios6没有这个self.edgesForExtendedLayout方法 所以ios6的view不能网上提高高度 就导致了界面显示后不统一 要想统一 就应该取消勾选
在ios7系统 tableView scrollView里面有穿透效果 使用默认的 并通过代码来判断当前系统 来调整代码做适配
---
只能imageView能在storyboard里设置图片的拉伸 中间一点拉伸
----
自定义控制器管理storyboard中的button初始样式 背景中间拉伸操作
------
当前控制器不想被push的时候出现底部tabbar勾选
但是对自定义tabbarview无效因为 因为自定义tabbarview的时候把tabbar remove了
所以不应该remove 而是放在上面 注意将bounds交给自定义的tabbarview
--------
自定义导航控制器 重写push方法
当push的时候隐藏底部tabbar
--------
---------
navigationController里设置导航条navigationbar的主题
initialize只调用一次
---------
批量设置UIBarButtonItem的字体属性主题
批量设置UIBarButtonItem的背景图片
-
----------------
tabview静态单元格实际开发中很少用到
因为ios6系统显示界面不一样 另外操作不方便
----------------
自定义MyTableViewController
将tableView的样式设定死 防止其他人创建的时候用不同的样式
-----------
@property (nonatomic, strong) Class desc;
---------------
UICollectionViewController 做九宫格
collectionView collectionViewController 初始化的时候必须要在init里指定布局方式
一般用流水布局 UICollectionViewFlowLayout
UICollectionViewFlowLayou(继承UICollectionViewLayout)
// NJProductViewController.m // 09-彩票(lottery) #import "NJProductViewController.h" #define NJIdentifier @"COLLECTION" @interface NJProductViewController () @end @implementation NJProductViewController - (id)init { // UICollectionViewLayout // 布局对象决定了将来CollectionView上每一个Cell显示的方式 // 创建一个布局对象 UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; // 设置每一个cell的宽高 (cell在CollectionView中称之为item) layout.itemSize = CGSizeMake(100, 100); // 设置item行与行之间的间隙 layout.minimumLineSpacing = 20; // 设置item列与列之间的间隙 // layout.minimumInteritemSpacing = 30; // 在初始化的时候传入自己创建的布局对象 if (self = [super initWithCollectionViewLayout:layout]) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationItem.title = @"产品推荐"; // 告诉系统将来需要创建什么样的cell(在获取cell之前必须先注册一个cell到系统中) [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NJIdentifier]; } #pragma mark - 数据源方法 // 告诉系统一共有多少组 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } // 告诉系统第section组有多少行 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 10; } // 告诉系统indexPath的第Section组的item行显示什么内容 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { // indexPath.section;// 第几组 // indexPath.item;// 第几个 // 从缓存池中获取cell UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NJIdentifier forIndexPath:indexPath]; // if (cell == nil) { // cell = [[UICollectionViewCell alloc] init] // } cell.backgroundColor = [UIColor greenColor]; return cell; } @end
-------------
cell的属性必须要赋值 否则会出现cell可重用导致的问题出现
---------------
属性为block用来保存block方法代码 self.option = 弹出提示框代码(MBProgressHUD) 用的时候直接调用
block快捷键 inlineBlock
block和函数的区别 block本质上和宏差不多 是指向代码的
运行的时候把某个代码拿来
----------
提示用户更新版本流程