標籤:style blog io ar color os sp for strong
六:獲得另一個控制項器,並實現跳轉
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *registerViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"registerViewController"]; registerViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController:registerViewController animated:YES completion:^{ NSLog(@"Present Modal View"); }];
其中registerViewController是第二個視圖中標識檢查器Storyboard ID的值
七:判斷IOS版本
判斷IOS是不是7.0以後的
if([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0) {
}
八:Button不同狀態下背景圖片
[_registerButton setBackgroundImage:[UIImage imageNamed:@"3signbutton-n.png"] forState:UIControlStateNormal];
[_registerButton setBackgroundImage:[UIImage imageNamed:@"3signbutton-s.png"] forState:UIControlStateHighlighted];
九:判斷裝置是3.5寸還是4寸
if ([[UIScreen mainScreen] currentMode].size.height == 480||[[UIScreenmainScreen] currentMode].size.height == 960)
{
//這是3.5寸的iPhone裝置
}
else
{ //這是4寸的iPhone裝置 }
十:viewDidLoad中調用
無論你是通過xib檔案還是重寫loadView方法建立UIViewController的view,在view建立完畢後,最終都會調用viewDidLoad方法,一般我們會在這裡做介面上的初始化操作,比如往view中添加一些子視圖、從資料庫或者網路載入模型資料裝配到子視圖中
- (void)viewDidLoad { [super viewDidLoad]; // 添加一個按鈕 UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; }
十一:樹形結構導航問題(UINavigationController)
1:如何修改第二頁的返回back文字
應該在第一頁的viewDidLoad裡面進行修改(假設從A介面push到B介面,希望改變B介面的返回按鈕標題,則在A介面中加入代碼),代碼如下:
-(void)viewDidLoad{UIBarButtonItem *backItem = [[[UIBarButtonItem alloc] init] autorelease]; backItem.title = @"返回"; self.navigationItem.backBarButtonItem = backItem;}
2:如何增加一個控制項在標題
在本頁的viewDidLoad裡面進行增加;代碼如下:
-(void)viewDidLoad{UIBarButtonItem* Done=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(DownShow)];self.navigationItem.rightBarButtonItem=Done;}-(void)DownShow{}
其中按鍵類型如下(帶有不同的表徵圖):
UIBarButtonSystemItemDone, UIBarButtonSystemItemCancel, UIBarButtonSystemItemEdit, UIBarButtonSystemItemSave, UIBarButtonSystemItemAdd, UIBarButtonSystemItemFlexibleSpace, UIBarButtonSystemItemFixedSpace, UIBarButtonSystemItemCompose, UIBarButtonSystemItemReply, UIBarButtonSystemItemAction, UIBarButtonSystemItemOrganize, UIBarButtonSystemItemBookmarks, UIBarButtonSystemItemSearch, UIBarButtonSystemItemRefresh, UIBarButtonSystemItemStop, UIBarButtonSystemItemCamera, UIBarButtonSystemItemTrash, UIBarButtonSystemItemPlay, UIBarButtonSystemItemPause, UIBarButtonSystemItemRewind, UIBarButtonSystemItemFastForward, UIBarButtonSystemItemUndo, UIBarButtonSystemItemRedo, UIBarButtonSystemItemPageCurl//只能在ToolBar上顯示
3:如何修改標題的色彩
self.navigationController.navigationBar.tintColor=[UIColor redColor];
4:增加其它UISegment,UISwith控制項
在本頁viewDidLoad中增加如下代碼,
UISegmentedControl *mySegment; mySegment = [[UISegmentedControl alloc] initWithFrame:CGRectMake(218.0f, 8.0, 100.0f, 30.0f)]; [mySegment insertSegmentWithTitle:@"分配" atIndex:0 animated:YES]; [mySegment insertSegmentWithTitle:@"處理" atIndex:1 animated:YES]; mySegment.segmentedControlStyle = UISegmentedControlStyleBar; mySegment.selectedSegmentIndex = 0; [self.navigationController.navigationBar addSubview:mySegment];
IOS開發基礎知識--片段2