iOS小知識(一)

1、註冊PCH文件

commond + N —>other —> PCH File —> Build Settings搜索pref  把建好的pct拖到框中。 


2、快捷設置變量名




3、

// 拿到UIViewController

- (UIViewController *)viewController {

    for (UIView* next = [self superview]; next; next = next.superview) {

        UIResponder *nextResponder = [next nextResponder];

        if ([nextResponder isKindOfClass:[UIViewController class]]) {

            return (UIViewController *)nextResponder;

        }

    }

    return nil;

}

[[self viewController] presentViewController:imagepicker animated:YES completion:nil];

4、

// 1 navigationItemUIBarButtonItem的偏移

UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];

leftBtn.frame = CGRectMake(0, 0, 65, 26);

[leftBtn setImage:[UIImage imageNamed:@"fanhui_btn_normal.png"] forState:UIControlStateNormal];

[leftBtn setTitle:@"返回" forState:UIControlStateNormal];

leftBtn.titleLabel.font = [UIFont systemFontOfSize:17];

[leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

[leftBtn addTarget:self action:@selector(checkAction) forControlEvents:UIControlEventTouchUpInside];


UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

negativeSpacer.width = -18;

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];


self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,leftButton, nil];


// 2

leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -16, 0, 0);

self.navigationItem.leftBarButtonItem = leftButton;


5、navigationBar的動畫

[self.navigationController setNavigationBarHidden:NO animated:NO];

self.navigationController.navigationBar.hidden = YES;


[self.navigationController setNavigationBarHidden:YES animated:YES];




待續中···



發佈了19 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章