美文网首页iOS开发
导航栏添加按钮

导航栏添加按钮

作者: 悄然林静 | 来源:发表于2019-01-17 13:58 被阅读0次
    UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];  
    [tools setBarTintColor:[UIColor whiteColor]];  
    NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];  
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UITabBarSystemItemContacts target:self action:@selector(save:)];  
    UIBarButtonItem *pulishButton = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UITabBarSystemItemContacts target:self action:@selector(pulish:)];  
    [pulishButton setTintColor:kMainColor];  
    [buttons addObject:saveButton];  
    [buttons addObject:pulishButton];  
    [tools setItems:buttons animated:NO];  
    UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools];  
    self.navigationItem.rightBarButtonItem = myBtn;  
    
    

    UIBarButtonItem *pulishButton = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UITabBarSystemItemContacts target:self action:@selector(pulish:)];
    [pulishButton setTintColor:kMainColor];
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UITabBarSystemItemContacts target:self action:@selector(save:)];
    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: pulishButton,saveButton,nil]];

    
    
    

    UIButton *saveButton=[UIButton buttonWithType:(UIButtonTypeCustom)];
    [saveButton setTitle:@"保存" forState:(UIControlStateNormal)];
    [saveButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    saveButton.layer.masksToBounds=YES;
    saveButton.layer.cornerRadius=3;
    saveButton.titleLabel.font=[UIFont systemFontOfSize:15];
    saveButton.backgroundColor=kMainColor;
    [saveButton addTarget:self action:@selector(save:) forControlEvents:UIControlEventTouchUpInside];

    pulishButton.frame = CGRectMake(0, 0, 50, 30);
    saveButton.frame=CGRectMake(0, 0, 50, 30);

    UIBarButtonItem *pulish = [[UIBarButtonItem alloc] initWithCustomView:pulishButton];
    UIBarButtonItem *save = [[UIBarButtonItem alloc] initWithCustomView:saveButton];

    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: pulish, save,nil]];

    
    
    

    相关文章

      网友评论

        本文标题:导航栏添加按钮

        本文链接:https://www.haomeiwen.com/subject/hdpqlqtx.html