ios按钮样式实现

QQ20130123-1.png

如图中toolbar上的按钮,请问是如何实现这种透明样式的? 设计师说iOS有自带的,这个看着像segmentcontrol,但自带的segmentcontrol好像没这种样式的,请教高人如何实现这种透明样式的按钮?

阅读 9.4k
1 个回答

确实,原生代码可以实现,但我还是要谴责一下你的设计师,这样说是非常不负责任的。
贴一下示例代码:

    UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(100.0f, 190.0f, 20.0f, 60.0f)];
    lb.backgroundColor = [UIColor blueColor];
    [self.window addSubview:lb];
    
    UILabel *lr = [[UILabel alloc] initWithFrame:CGRectMake(120.0f, 190.0f, 20.0f, 60.0f)];
    lr.backgroundColor = [UIColor redColor];
    [self.window addSubview:lr];

    UILabel *ly = [[UILabel alloc] initWithFrame:CGRectMake(140.0f, 190.0f, 20.0f, 60.0f)];
    ly.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:ly];
    
    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 200.0f, 320.0f, 44.0f)];
    toolBar.barStyle = UIBarStyleBlackOpaque;
    toolBar.alpha = 0.9f;
    [self.window addSubview:toolBar];
    
    UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"确定", @"取消"]];
    control.tintColor = [UIColor blackColor];
    control.segmentedControlStyle = UISegmentedControlStyleBar;
    control.enabled = NO;
    control.frame = CGRectMake(10.0f, 7.0f, 120.0f, 30.0f);
    [toolBar addSubview:control];

在ToolBar下边放了红黄蓝三个彩条,用来衬托ToolBar的透明。效果如图:
示例

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题