gpt4 book ai didi

iphone - 具有方向或箭头主题的 UISegmentedControl

转载 作者:行者123 更新时间:2023-11-28 22:41:04 25 4
gpt4 key购买 nike

我已经使用 BASequenceControl 实现了带有 Direction 主题的 UISegmentedControl 来自 cocoacontrols.com

我添加了 BASequenceControl.h BASequenceControl.m 类(class)和所需图片来自 GitHub

太棒了。它对我来说工作正常..但是我对最后一段部分提示有疑问。

它显示了最后一段的垃圾空间。

原始屏幕截图

enter image description here

我需要这样

enter image description here

我实现的代码

        #import "BASequenceControl.h"

BASequenceControl *bASequenceControl = [[BASequenceControl alloc] init];
bASequenceControl.frame = CGRectMake(10, 10, 200, 44);
[bASequenceControl addSegmentWithTitle:@"First" animated:NO];
[bASequenceControl addSegmentWithTitle:@"Second" animated:NO];

bASequenceControl.leftMargin = -22;
bASequenceControl.rightMargin = 0;
bASequenceControl.overlapWidth = 22;

[self.view addSubview:bASequenceControl];

感谢任何帮助。

谢谢。

最佳答案

这是一个非常简单的修复。您必须编辑 BASequenceControl.m 文件,或者您可以复制该类并重命名它。

导致问题的行在 drawRect: 中,它基本上在控件的整个背景上绘制了灰色箭头。在空白区域创建漂亮的渐变。

[passiveSegmentImage drawInRect:CGRectMake(-passiveSegmentImage.size.width, 0,
w + 2 * passiveSegmentImage.size.width, h)];

您可以将其更改为:

[passiveSegmentImage drawInRect:CGRectMake(0, 0,
w, h)];

现在你必须告诉控件它不应该是不透明的。像这样更新初始值设定项。

- (void)awakeFromNib {
_selectedSegmentIndex = -1;
[self setOpaque:NO];
[super awakeFromNib];
}

- (id)init {
if ((self = [super init])) {
[self setOpaque:NO];
_selectedSegmentIndex = -1;
}
return self;
}

这是非常快速和肮脏的,你可以潜在地使用一个属性来设置它。然后向 BaseAppKit 提交拉取请求,但我会把它留给你。这是一个要点,您可以将其直接复制并粘贴到 BASequenceControl.m 中以修复悬垂。 https://gist.github.com/4632686

编辑:确保您使用 init 作为初始值设定项,然后使用 setFrame:(我不太确定为什么 initWithFrame:在类里面没有被覆盖。)

BASequenceControl *control = [[BASequenceControl alloc] init];
[control setFrame:CGRectMake(0, 0, 300, 40)];

Fixed control, green for dramatic effect

戏剧效果的绿色背景

关于iphone - 具有方向或箭头主题的 UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514712/

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