2

iOS 7 より前は、色付きの画像をセグメント コントローラーに追加するのは簡単でしたが、現在は画像を追加すると、実際の色ではなく、デフォルトの色合いで画像のみが表示されます。

誰でもこれについて考えていますか? もしそうなら、親切に私を助けてください.

事前にサンクス。

4

3 に答える 3

3

次のように修正してください: imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal

UIImage *segmentImage = [UIImage imageNamed:@"Example"];

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
     segmentImage = [segmentImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

[self.control insertSegmentWithImage:segmentImage atIndex:i animated:NO];
于 2013-10-08T11:47:00.250 に答える
0

これはあなたを助けるかもしれません

UIImage *segmentSelected = [[UIImage imageNamed:@"Off.png"]
                            resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentUnselected = [[UIImage imageNamed:@"On.png"]
                              resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentSelectedUnselected =
[UIImage imageNamed:@"dividerOn.png"];
UIImage *segUnselectedSelected =
[UIImage imageNamed:@"dividerOff.png"];

[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
                                           forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentSelected
                                           forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
                                           forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected
                             forLeftSegmentState:UIControlStateNormal // | UIControlStateHighlighted
                               rightSegmentState:UIControlStateSelected
                                      barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected
                             forLeftSegmentState:UIControlStateHighlighted
                               rightSegmentState:UIControlStateSelected
                                      barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
                             forLeftSegmentState:UIControlStateSelected
                               rightSegmentState:UIControlStateNormal //| UIControlStateHighlighted)
                                      barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
                             forLeftSegmentState:UIControlStateSelected
                               rightSegmentState:UIControlStateHighlighted
                                      barMetrics:UIBarMetricsDefault];

UIFont *font = [UIFont systemFontOfSize:16.0f];
UIColor *textColor = [UIColor darkGrayColor];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                            font, @"NSFontAttributeName",
                            textColor, @"NSForegroundColorAttributeName",
                            nil];

[[UISegmentedControl appearance] setTitleTextAttributes:attributes
                                               forState:UIControlStateNormal];
于 2013-10-04T05:53:46.043 に答える