码迷,mamicode.com
首页 > 移动开发 > 详细

ios 将segment添加到nav上

时间:2015-02-23 00:13:05      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

/* 初始化导航按钮 */  
{
            credits = [ [ [ UIBarButtonItem alloc ]  
                        initWithTitle:@"Credits"  
                        style: UIBarButtonItemStylePlain  
                        target: appDelegate  
                        action:@selector(credits) ]  
                    autorelease ];  
            self.navigationItem.rightBarButtonItem = credits;  
 
            segmentedControl = [ [ UISegmentedControl 
alloc ] initWithItems: nil ];  
            segmentedControl.segmentedControlStyle = 
UISegmentedControlStyleBar;  
 
            [ segmentedControl insertSegmentWithTitle: 
@"Bunnies" atIndex: 0  
                animated: NO  
            ];  
            [ segmentedControl insertSegmentWithTitle: 
@"Ponies" atIndex: 1  
                animated: NO  
            ];  
 
            [ segmentedControl addTarget: self action: 
@selector(controlPressed:)  
                forControlEvents:UIControlEventValueChanged  
            ];  
 
            self.navigationItem.titleView = segmentedControl;  
            segmentedControl.selectedSegmentIndex = 0;  
        }  
        return self;  
}  
 
- (void)controlPressed:(id) sender {  
        [ self setPage ];  
}  
 
- (void)setPage {  
        int index = segmentedControl.selectedSegmentIndex;  
 
        if (index == 0) {  
            textView.text = @"OMG Bunnies!";  
        } else {  
            textView.text = @"OMG Ponies";  
        }  
}  

  

ios 将segment添加到nav上

标签:

原文地址:http://www.cnblogs.com/JJFly/p/4297807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!