gpt4 book ai didi

ios - UISegmentedControl 图像突出显示 iOS 中的错误?

转载 作者:行者123 更新时间:2023-11-29 10:48:35 25 4
gpt4 key购买 nike

我有一个应用程序,我想在其中使用 Instagram 中的按钮自定义分段控件。我曾经这样做过

 [[UISegmentedControl appearanceWhenContainedIn:[UISearchBar class], nil] setSegmentedControlStyle:UISegmentedControlStyleBar];
[[UISegmentedControl appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor:[UIColor clearColor]];

[[UISegmentedControl appearance] setBackgroundImage:[UIImage imageNamed:@"back_bg.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:[UIImage imageNamed:@"white_btn.png"]

forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"segcontrol_uns-sel.png"]
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"segcontrol_sel-uns.png"]
forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];

但是当我选择按钮时,它会突出显示除分区图像之外的部分。所以它看起来有线。有人可以帮我解决这个问题吗?

最佳答案

试试这个:

UIImage *defaultBgImage,*selectedBgImage,*segcontrol_uns,*segcontrol_sel;

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)])
{
defaultBgImage = [[UIImage imageNamed:@"back_bg.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
selectedBgImage = [[UIImage imageNamed:@"white_btn.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
segcontrol_uns = [[UIImage imageNamed:@"segcontrol_uns-sel.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
segcontrol_sel = [[UIImage imageNamed:@"segcontrol_sel-uns.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
else
{
defaultBgImage = [UIImage imageNamed:@"back_bg.png"];
selectedBgImage = [UIImage imageNamed:@"white_btn.png"];
segcontrol_uns = [UIImage imageNamed:@"segcontrol_uns-sel.png"];
segcontrol_sel = [UIImage imageNamed:@"segcontrol_sel-uns.png"];
}

[[UISegmentedControl appearance] setBackgroundImage:defaultBgImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[[UISegmentedControl appearance] setBackgroundImage:selectedBgImage
forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

[[UISegmentedControl appearance] setDividerImage:segcontrol_uns forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];

[[UISegmentedControl appearance] setDividerImage:segcontrol_sel forLeftSegmentState: UIControlStateSelected rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];

关于ios - UISegmentedControl 图像突出显示 iOS 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21432679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com