ios - 段控制段的大小

标签 ios objective-c

为了向分段控件添加图像,如何确定分段控件中控件框的尺寸? 例如,上图中的分段控件中有四个框,但如果分段控件本身被拉伸(stretch),它们也可以被拉伸(stretch)。我怎样才能找出任何框的大小,以便我知道创建要为控件设置的图像有多大?

更新 - 当我尝试使用下面的 widthForSegmentAtIndex 时,此代码给出了 expected expression 错误

- (IBAction)segmentChosen:(id)sender {
    UISegmentedControl *segmentedControl = (UISegmentedControl*) sender;
    switch ([segmentedControl selectedSegmentIndex]) {
        case 0:
            CGFloat widthOfWantedSegment = [segmentedControl widthForSegmentAtIndex:0];

最佳答案

How can I find out the size of any of the boxes so that I know how big to create an image I wish to set for the control?

通过使用UISegmentController实例方法-widthForSegmentAtIndex:

引用号:UISegmentedControl Apple Doc


CGFloat f_widthOfWantedSegment = [segmentController widthForSegmentAtIndex:1];

关于ios - 段控制段的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23725095/

相关文章:

ios - 从 iPhone 应用程序 Expressjs/Nodejs 后端发送 JSON 发布数据

objective-c - Objective C、iOS,如何将几个 int 变量附加到属于 IBOutletCollection 一部分的 UIImageView?

ios - 获取 SCNText 中的 String 属性

ios - 仅在iPod中崩溃

ios - 关于使用 PHAuthorizationStatus.authorizationStatus() 的问题

ios - 云上的 HAP 将如何工作?

iphone - Objective C iPhone 何时将对象引用设置为 nil

ios - Swift4.1 : How to remove delivered notification from notification list without open application

ios - Xcode 7 警告 : object file was built for newer iOS version than being linked

ios - 使用 Stripe 的 Swift 应用程序 - 类型 'STPCustomer' 没有成员 'decodedObject'