zoukankan      html  css  js  c++  java
  • UIToolbar

    - (void)viewDidLoad {
      [super viewDidLoad];
      [self AddToolBars];

    }

    -(void)AddToolBars
    {
    UIToolbar *toolBarTop=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 50)];
    [toolBarTop setBarStyle:UIBarStyleDefault];
    [self.view addSubview:toolBarTop];
    [toolBarTop setBarTintColor:[UIColor redColor]];

    UIBarButtonItem *item1=[[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleDone target:self action:@selector(toolBarItemCilck)];
    item1.width=20;

    UIBarButtonItem *item2=[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:self action:@selector(toolBarItemCilck)];
    item2.width=20;

    UIBarButtonItem *item4=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];
    item2.width=20;


    UIBarButtonItem *item3=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil ];

    ToolBarItem *textField=[[ToolBarItem alloc] init];//自定义的UIview
    textField.frame=CGRectMake(0, 0, 200, 30);
    [textField.button addTarget:self action:@selector(btnClick1) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *item5=[[UIBarButtonItem alloc]initWithCustomView:textField];//自定义的Item


    [toolBarTop setItems:[NSArray arrayWithObjects:item1,item5,nil] animated:YES];

    }

    @interface ToolBarItem : UIView

    -(id)init
    {
    self= [super init];
    _button=[[UIButton alloc] initWithFrame:CGRectMake(70, 0, 30, 30)];
    [_button setTitle:@"Click" forState:UIControlStateNormal];
    _button.backgroundColor=[UIColor grayColor];

    UITextField *t1=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
    t1.placeholder=@"Hello";
    t1.backgroundColor=[UIColor orangeColor];

    [self addSubview:t1];
    [self addSubview:_button];

    return self;
    }

  • 相关阅读:
    机器学习【工具】:Numpy
    机器学习【算法】:KNN近邻
    【笔记】:字典内部剖析
    【笔记】:谁偷了我的内存?
    什么是RESTful框架
    音频下载服务
    【模块】:Requests(二)
    【模块】:Weakref
    异步Web服务(二)
    【Win10】UAP/UWP/通用 开发之 RelativePanel
  • 原文地址:https://www.cnblogs.com/zhangleixy/p/4975889.html
Copyright © 2011-2022 走看看