IOS中標籤視圖和Block

來源:互聯網
上載者:User

標籤:標籤   控制項   uitabbarcontroller   block   

標籤視圖控制器 - UITabBarController自訂UITabBarItem自訂導覽列和標籤欄背景圖片三個視圖控制器的綜合使用
一. 標籤視圖控制器  UITabBarControllerUITabBarController有以下重要屬性viewControllers   顯示的視圖控制器tabBar                  標籤欄delegate                協議
tabBar 是 UITabBar對象, 包含多個UITabBarItem, 每個tanBarItem對應一個viewController. tabBar高度為49
當tabBarItem超過五個時, 系統會自動增加一個更多按鈕,點擊更多按鈕,沒有在底部出現的那些按鈕會以列表形式顯示出來
UIAppearance如果想通過一鍵設定所有導航視圖控制器的顏色,類似於QQ的一鍵換膚操作, 可以通過UIAppearance協議來進行操作, 通過它可以對一些控制項進行自訂色彩等
UITabBarController * tab = [[UITabBarController alloc] init];    tab.delegate = self;    [tab setHidesBottomBarWhenPushed:NO];        NSArray * arr = [NSArray arrayWithObjects:nav,nav2,nav3,nav4,nav5,nav6, nil];    [tab setViewControllers:arr];    //整個一條的顏色    [tab.tabBar setBarTintColor:[UIColor whiteColor]];    //每個表徵圖的顏色    [tab.tabBar setTintColor:[UIColor orangeColor]];

總結UITabBarController是項目開發中常見的配置樣式,與UINavigationController不同,它的viewController都是並列的,而UINavigationController的則是層次性的
UITabBatController,UINavigationController和UITableViewController,通常都是組合出現,這種布局方式特別常見,一定要熟練應用
UITabBarController可以嵌套UINavigationController
UINavigationController也可以嵌套UITabBatController

IOS  Block用法在IOS中,定義 用" ^ "來表明block變數, 內容是包含在" {}"中的,並且和C語言一樣,用" ; "來表示語句的結束
int multiplier = 7;
int (^myBlock)(int) = ^(int num){return num * multiplier; };
"^"聲明這是一個block, "myBlock"為變數名
block返回值類型為int類型類型為int的參數參數名為"num"


//無傳回型別 無參數類型的block-(void)testFirstBlock{    void (^myBlock)() = ^(){        NSLog(@"我輸了>3<");    };    NSLog(@"比比誰先走");    myBlock();}-(void)testSecondBlock{    void (^twoBlock)(NSString *) = ^(NSString * str){        NSLog(@"str == %@",str);    };    twoBlock(@"手拉手 一起走");    twoBlock(@"豬點點");}//無傳回值 多個參數-(void)testThirdBlock{    void (^thirdBlock)(NSString *,int) = ^(NSString * str,int a){        NSLog(@"int == %d,str == %@",a,str);    };    thirdBlock(@"(?????)",55555);}//有傳回值 有參數-(void)testForthBlock{    int (^forthBlock)(NSString *,NSInteger) = ^(NSString * value,NSInteger num){                int strValue = [value intValue];                return strValue+num;    };        int d = forthBlock(@"77",2);        NSLog(@"(?????)a == %d",d);}//改變背景顏色-(void)testColorBlock{    void (^myBlock)(UIColor *) = ^(UIColor * color){        [self.view setBackgroundColor:color];    };    self.teseBlock = myBlock;    NSLog(@"textBlock == %@",self.teseBlock);}


Block注意事項由於block所建立的變數分為兩個記憶體地區,分別是全域區和棧區,因此在IOS中如果使用block的成員變數或者屬性時,需要將其copy到堆記憶體中.
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.