[英]Can I redraw a UISegmentedControl programatically? How?
Say I have a UITextField (default blank), a UISegmentedControl (default 2 segments named "1" & "2"), and a UILabel (default text "None") in my nib . 假设我的笔尖中有一个UITextField(默认为空白),一个UISegmentedControl(默认为2个分别名为“ 1”和“ 2”的段)和一个UILabel(默认文本为“ None”)。 I want to be able to do the following: 我希望能够执行以下操作:
I know how to set an IBAction that will catch the number entered in the UITextField, but how do #2 above, that is how do I "redraw" the UISegmentControl to have 3 segments named "1", "2", and "3?" 我知道如何设置一个IBAction来捕获在UITextField中输入的数字,但是上面的#2怎么做,也就是我如何“重绘” UISegmentControl使其具有3个分别为“ 1”,“ 2”和“ 3”的段?
I know how to do #3. 我知道该怎么做#3。
You can do it by using the insertSegmentWithTitle:(NSString *) atIndex:(NSUInteger) animated:(BOOL) method. 您可以通过使用insertSegmentWithTitle:(NSString *)atIndex:(NSUInteger)animation:(BOOL)方法来实现。
Like: 喜欢:
int indexOfSegment = yourSegmentController.numberOfSegments;
[yourSegmentController insertSegmentWithTitle:yourTextfield.text atIndex:indexOfSegment animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.