iphone - 有没有办法使 UISegmentedControl 按钮大小不同?

标签 iphone objective-c cocoa-touch uisegmentedcontrol

我有一个包含 2 个项目的 UISegmentedControl。

有没有办法让左边的item比右边的item大一点?

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:symbol,@"+", nil]];
        [segmentedControl addTarget:self action:@selector(segmentedControlChanged:)forControlEvents:UIControlEventValueChanged];
        [segmentedControl setWidth:45 forSegmentAtIndex:0];
        [segmentedControl setWidth:20 forSegmentAtIndex:1];
        segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
        segmentedControl.frame = CGRectMake(0,0,300,30);
        segmentedControl.momentary = NO;
        [segmentedControl setSelectedSegmentIndex:0];

        self.navigationItem.titleView = segmentedControl;

不起作用。

最佳答案

是的,你可以这样做:-

    [*yoursegmentcontrolobjectname* setWidth:45 forSegmentAtIndex:0];
    [*yoursegmentcontrolobjectname* setWidth:15 forSegmentAtIndex:1];   

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:symbol,@"+", nil]];
        [segmentedControl addTarget:self action:@selector(segmentedControlChanged:)forControlEvents:UIControlEventValueChanged];
        segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
        segmentedControl.frame = CGRectMake(0,0,300,30);
        segmentedControl.momentary = NO;
        [segmentedControl setSelectedSegmentIndex:0];

        self.navigationItem.titleView = segmentedControl;

现在添加这两行就可以了

        [segmentedControl setWidth:45 forSegmentAtIndex:0];
        [segmentedControl setWidth:20 forSegmentAtIndex:1];

关于iphone - 有没有办法使 UISegmentedControl 按钮大小不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7157571/

相关文章:

iphone - 使用 CAAnimation 检测正在动画的 uiview subview 的触摸

ios - 如何让我的 iOS 应用程序在 Facebook 和 Twitter 等照片共享选项中可见?

iphone - 有关于如何在 Mac/PC 和 iOS 之间使用 iTunes 文件共享传输图片的教程吗?

iphone - 如何解决 -[__NSCFString JSONValue] : unrecognized selector sent to instance when application terminates?

ios - iTunes Connect 技术角色访问权限;作为开发人员的利弊

ios - 将密码和 session token 保存在钥匙串(keychain)中

ios - IOS/Objective-C:360图像旋转问题

iphone - 适用于 Android 操作系统的 PayPal 应用内购买 - 服务器/客户端模型

ios - 隐藏 SecItemUpdate 上的 TouchId 弹出窗口

ios - 使用 userDefaults 保存自定义背景颜色