시뮬레이터를 실행할 때 다른 요소의 모든 색을 반대로하면이 코드에서 색인에 잘못된 것이 무엇인지 찾을 수 없습니다.UISegmentedControl에서 모든 세그먼트의 색조 색 순서가 왜 바뀌 었습니까? 그것을 고치는 방법?
UISegmentedControl의 마지막 서브 뷰가에 남아#import "ViewController3.h"
@interface ViewController3()
@property (strong, nonatomic) IBOutlet UIView *segments;
@property (weak, nonatomic) IBOutlet UILabel *label;
@end
@implementation ViewController3
- (void)viewDidLoad {
[super viewDidLoad];
//creating textField programmatically
// UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 20)];
// textField.borderStyle = UITextBorderStyleRoundedRect;
// textField.font = [UIFont systemFontOfSize:15];
// textField.placeholder = @"enter text here";
// textField.autocorrectionType = UITextAutocorrectionTypeNo;
// textField.keyboardType = UIKeyboardTypeDefault;
// textField.returnKeyType = UIReturnKeyDone;
// textField.clearButtonMode = UITextFieldViewModeWhileEditing;
// textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
// [self.view addSubview:textField];
//setting tint color for segments
[[_mysegment.subviews objectAtIndex:0] setTintColor:[UIColor redColor]];
[[_mysegment.subviews objectAtIndex:1] setTintColor:[UIColor blueColor]];
[[_mysegment.subviews objectAtIndex:2] setTintColor:[UIColor greenColor]];
[[_mysegment.subviews objectAtIndex:3] setTintColor:[UIColor purpleColor]];
[[_mysegment.subviews objectAtIndex:4] setTintColor:[UIColor orangeColor]];
//to preload everyview before hand
[email protected]"1";
_image1.image = [UIImage imageNamed:@"fruits.png"];
_colorToBeDisplayedInView.backgroundColor = [UIColor redColor];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)segmentControl:(id)sender {
if (_mysegment.selectedSegmentIndex==0)
{
[email protected]"1";
_image1.image = [UIImage imageNamed:@"fruits.png"];
_colorToBeDisplayedInView.backgroundColor = [UIColor redColor];
}
else if (_mysegment.selectedSegmentIndex==1)
{
[email protected]"2";
_image1.image = [UIImage imageNamed:@"airplane.png"];
_colorToBeDisplayedInView.backgroundColor = [UIColor blueColor];
}
else if (_mysegment.selectedSegmentIndex==2)
{
[email protected]"3";
_image1.image = [UIImage imageNamed:@"boat.png"];
_colorToBeDisplayedInView.backgroundColor = [UIColor greenColor];
}
else if (_mysegment.selectedSegmentIndex==3)
{
[email protected]"4";
_image1.image = [UIImage imageNamed:@"arctichare.png"];
_colorToBeDisplayedInView.backgroundColor = [UIColor purpleColor];
}else
{
[email protected]"5";
_image1.image = [UIImage imageNamed:@"cat.png"];
_colorToBeDisplayedInView.backgroundColor = [UIColor orangeColor];
}
}
@end
그것이 이미 질문에 있었는지 확실하지 않습니다. 시뮬레이터의 스크린 샷 링크는 다음과 같습니다. https://i.stack.imgur.com/UZ9qC.png – N4SK
'UISegmentaionControl'에서 두 세그먼트만으로 같은 코드를 시도한 다음, 그 코드가주는 O/P를 확인하십시오. –
틴트 색상을 직접 지정했지만 일부 조건에서는 좋지 않습니다. 그래서 문자열을 기반으로 세그먼트에 대한 색상을 설정 ... – Marking