您的位置:首页 > 产品设计 > UI/UE

自定义UIBarButtonItem

2016-01-05 10:23 453 查看
//单个自定义按钮

 UIButton *button =[UIButton
buttonWithType:UIButtonTypeCustom];

    button.frame =CGRectMake(0,
0, 50,
50);

    UIBarButtonItem*Button = [[UIBarButtonItem
alloc]
initWithCustomView:button];

    self.navigationItem.leftBarButtonItem = Button;
//多个按钮

    UIBarButtonItem *btn = [[UIBarButtonItem
alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
target:self
action:@selector(click:)];

    UIBarButtonItem btnOne = [[UIBarButtonItem
alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPause
target:self
action:@selector(click1:)];

    [self.navigationItem
setRightBarButtonItems:[NSArray
arrayWithObjects:btn,btnOne,nil]];

//自定义View上随意放置button

  UIView *view = [[UIView alloc]initWithFrame:CGRectMake(kWidth * 4 / 5, 0, 75, 30)];

    //分享按钮

    UIButton *sharebutton = [UIButton buttonWithType:(UIButtonTypeCustom)];

    sharebutton.frame =  CGRectMake(5, 0, 30, 30);

    [view addSubview:sharebutton];

    //收藏按钮

    self.collectbutton = [UIButton buttonWithType:(UIButtonTypeCustom)];

    self.collectbutton.frame = CGRectMake(45, 0, 30, 30);

    [view addSubview:self.collectbutton];

    UIBarButtonItem *collectItem = [[UIBarButtonItem alloc] initWithCustomView:view];

    self.navigationItem.rightBarButtonItem =
collectItem;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: