自定義字體時設置字體大小時不能在.號后加任何
多用繼承/分類/擴展。不僅僅是對于UIViewcontroller 還有對于一些控件, 這對于整體的架構,以及后期的維護很重要。但是寫繼承的時候要注意分塊兒,不然隨著代碼的迭代繼承會成為你的累贅
繼承/多態(tài)/封裝。越看越重要
都能夠讓代碼解耦、模塊化,清晰起來 ,對于書寫代碼的思路也有很好的提升。
所以一開始拿到需求的時候,要先對整體有一個總的思路(框架),不僅僅是Nav/Tab 還有對于一些控件/UIView。webview內(nèi)設置屬性可以用js代碼(h5),可以讓webView看起來很酷
字典可以是多個數(shù)組的集合,字典取value指以及數(shù)組取value值十分重要
滑動控制器的contentSize
scrollView.contentSize = CGSizeMake(self.view.frame.size.width,CGRectGetMaxY(view.lastLabel.frame)+ 40);
或者可以用布局寫scrollView距底為0
- 彈框動畫
-(void)animationAlert:(UIView *)view{
CAKeyframeAnimation *popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
popAnimation.duration = 0.4;
popAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.01f, 0.01f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1f, 1.1f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)],
[NSValue valueWithCATransform3D:CATransform3DIdentity]];
popAnimation.keyTimes = @[@0.0f, @0.5f, @0.75f, @1.0f];
popAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[view.layer addAnimation:popAnimation forKey:nil];
}
- 把數(shù)據(jù)源綁定到UIButton上
1、可以通過自定義Btn(繼承),在此上新增屬性作為參數(shù)
1
//寫一個wxzBtn繼承自UIButton,為了可以重寫數(shù)據(jù)。因為UIBtton本身不能
@interface wxzBtn : UIButton
//Btn所綁定的東西
@property (nonatomic,strong) NSString * titlestring;
@end
@interface Mycell : UITableViewCell
@property (nonatomic,strong) wxzBtn * confirmBtn;
@end
2
在創(chuàng)建 confirmBtn按鈕時是根據(jù)類wxzBtn創(chuàng)建
self.confirmBtn = [[wxzBtn alloc] init];
3
在按鈕點擊之前重寫titlestring的值
cell.confirmBtn.titlestring = @"1111";
[cell.confirmBtn addTarget:self action:@selector(confirmBtnClick:) forControlEvents:UIControlEventTouchUpInside];
4
- (void)confirmBtnClick:(wxzBtn *)btn{
NSLog(@"%@",btn.titlestring);
}
- 知道返回數(shù)據(jù)的Json格式特別重要,因為在tableview等一些控制器里有section和row 這里需要對解析格式特別熟練 比如數(shù)組A里有一個字典---字典里有字符串,數(shù)組B---數(shù)組B里又有字符串
- 加載本地的gif圖片
- (void)viewDidLoad {
[super viewDidLoad];
_imageIV = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
[self.view addSubview:_imageIV];
_imageIV.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"party_sel_00000" ofType:@"png"]];
_imageIV.backgroundColor = [UIColor redColor];
[self configMainImageView];
}
- (void)configMainImageView {
self.imageIV.animationImages = [self initialImageArray];
self.imageIV.animationDuration = 3.f;
self.imageIV.animationRepeatCount = 1;
[self.imageIV startAnimating];
[self performSelector:@selector(clearAinimationImageMemory) withObject:nil afterDelay:3.0f];
}
- (NSArray *)initialImageArray {
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
for (int i = 0; i < 26; i++) {
NSString * imageName ;
if (i >= 10) {
imageName = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"party_sel_000%d@2x",i]ofType:@"png"];
}else{
imageName = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"party_sel_0000%d@2x",i]ofType:@"png"];
}
UIImage *image = [UIImage imageWithContentsOfFile:imageName];
[imageArray addObject:image];
}
return imageArray;
}
- (void)clearAinimationImageMemory {
[self.imageIV stopAnimating];
self.imageIV.animationImages = nil;
}
self.userInteractionEnabled = NO;
設置了當前self不能和用戶交互,相當于顯示了一張圖片VIew里的跳轉
1、獲取當前界面(VC)的Nav 然后Push
2、獲取當前窗口的可見控制器Pushbtn的img和title的內(nèi)邊距設置
在設置內(nèi)邊距的時候直接設置img和title的位置就可以了。銷毀某個View時
正確的做法
1、[view removeFromSuperview ];
2、view = nil;
原因如下:
_View = nil;
[_View removeFromSuperview];
//理解內(nèi)存管理, 一個變量的何時銷毀。
//_View 在視圖上的時候是有兩個引用,一個父視圖,一個——_View變量,先把——_View設置nil,就不能執(zhí)行這句話了
[nil removeFromSuperview];
KVC真的很好用! 不管是在什么情況下都可以取到某些特定的值
利用貝塞爾曲線切view的邊角
//創(chuàng)建
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 70)];
myLabel.text = @"Hello,world";
myLabel.font = [UIFont systemFontOfSize:20.0];
myLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:myLabel];
CGFloat radius = 21.0f;
//利用貝塞爾曲線為label的邊距設置
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:myLabel.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerBottomRight|UIRectCornerTopLeft cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer * mask = [[CAShapeLayer alloc] init];
mask.lineWidth = 5;
// kCGLineCapButt:無端點
kCGLineCapRound:圓形端點
kCGLineCapSquare:方形端點(樣式上和kCGLineCapButt是一樣的,但是比kCGLineCapButt長一點)
//
mask.lineCap = kCALineCapSquare;
// 帶邊框則兩個顏色不要設置成一樣即可
mask.strokeColor = [UIColor redColor].CGColor;
mask.fillColor = [UIColor yellowColor].CGColor;
mask.path = path.CGPath;
[myLabel.layer addSublayer:mask];
- 加載幀動畫
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView *animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 77/2, 118/2)];
animatedImageView.image = [UIImage imageNamed:@"personaldata_reward"];
//圖片控件添加到視圖上面去
[self.view addSubview:animatedImageView];
//創(chuàng)建一個可變數(shù)組
NSMutableArray *animationImages=[NSMutableArray array];
for(int I=1;I<=12;I++){
//通過for 循環(huán),把我所有的 圖片存到數(shù)組里面
NSString *imageName=[NSString stringWithFormat:@"personaldata_reward%d",I];
UIImage *image=[UIImage imageNamed:imageName];
[animationImages addObject:image];
}
// 設置圖片的序列幀 圖片數(shù)組
animatedImageView.animationImages=ary;
//動畫重復次數(shù) 0代表無限選婚
animatedImageView.animationRepeatCount=1;
//動畫執(zhí)行時間,多長時間執(zhí)行完動畫
animatedImageView.animationDuration=3.0;
//開始動畫
if (! animatedImageView.isAnimating) {
[animatedImageView startAnimating];
}
//添加一個按鈕,把幀動畫添加到按鈕里
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(HCSystemWidth-50, HCSystemHeight/2+HCScaleHeight(100), 77/2, 118/2)];
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
[btn addSubview:animatedImageView];
[btn bringSubviewToFront:animatedImageView];
[self.view addSubview:btn];
}
離開界面的時候的
[animatedImageView stopAnimating];