iOS開發:導航欄上實現tab--標題位置添加多個button

我是直接在標題位置添加兩個button 加載兩個viewcontroller 簡單粗暴實現頂部切換卡

UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)/2-60, 0, 120, 30)];
    _tabMeet = [UIButton buttonWithType:UIButtonTypeCustom];
    _tabMeet.frame = CGRectMake(0, 0, 40, 30);
    [_tabMeet setTitle:@"邂逅" forState:UIControlStateNormal];
    [_tabMeet setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [titleView addSubview:_tabMeet];
    _tabNearby = [UIButton buttonWithType:UIButtonTypeCustom];
    _tabNearby.frame = CGRectMake(80, 0, 40, 30);
    [_tabNearby setTitle:@"附近" forState:UIControlStateNormal];
    [_tabNearby setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [_tabNearby addTarget:self action:@selector(showNearby:) forControlEvents:UIControlEventTouchUpInside];
    [titleView addSubview:_tabNearby];
    self.navigationItem.titleView = titleView;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章