为了向分段控件添加图像,如何确定分段控件中控件框的尺寸? 例如,上图中的分段控件中有四个框,但如果分段控件本身被拉伸(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/