IOS开发基础知识--碎片2

六:获得另一个控件器,并实现跳转

复制代码
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");
    
}];
复制代码

 另一种用segue连接:

如果在storyboard中当前的ViewController和要跳转的ViewController之间的segue之间存在,则可以执行performSegueWithIdentifier:sender:这个方法实现跳转。

  比如:[self performSegueWithIdentifier:@"go" sender:self];

     其中,go为自己定义的segue标识符。

其中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];
复制代码

 

posted @   踏浪帅  阅读(692)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述
历史上的今天:
2013-11-26 Jquery重新学习之二[属性attr(),removeAttr(),prop(),removeProp()]
点击右上角即可分享
微信分享提示