从某些UISegmentedControl索引获取帧? [英] Get frame from certain UISegmentedControl index?

查看:94
本文介绍了从某些UISegmentedControl索引获取帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用UIPopoverController并使用 presentPopoverFromRect API。我现在正在做的只是将它设置为我整个UISegmentedControl的框架。但是我希望比这更精确。有没有办法在UISegmentedControl中获取特定索引的框架?

In my app, I use a UIPopoverController and I use the presentPopoverFromRect API. What I am doing now is just setting it to the frame of my whole UISegmentedControl. However I want to be more precise than this. Is there any way to get the frame of a specific index in the UISegmentedControl?

谢谢!

推荐答案

如果段相等,为什么不将控件的宽度除以所选段的数量(+1因为编号从0开始)?
编辑:喜欢这个

If the segments are equal, why not just divide the width of the control by the number of the selected segment (+1 because numbering starts at 0)? Like this

-(void)showPopover:(id)sender {
    if ((UISegmentedControl*)sender.selectedSegmentIndex == 0)
        [self.popover presentPopoverFromRect:CGRectMake(self.segmentedControl.frame.size.width/6, self.segmentedControl.frame.origin.y, aWidth, aHeight)]
}

超过6(我假设有3段实施),因为你有获得该段的中心,3将它放在线上。如果你在这里做一些简单的数学运算(让我们假设整个控制是60像素宽),那么60/3 yeilds 20.因为每个段宽20 px,宽度60超过6会产生正确答案10。

It's over 6 (I'm assuming a 3 segment implementation), because you have to get the center of the segment, and 3 would put it on the lines. And if you do some simple math here (let's assume the whole control is 60 px wide), then 60/3 yeilds 20. Because each segment is 20 px wide, the width of 60 over six yields the correct answer 10.

这篇关于从某些UISegmentedControl索引获取帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆