【问题标题】:UIStepper only show minus signUIStepper 只显示减号
【发布时间】:2012-05-15 10:38:45
【问题描述】:

我试图通过使用层,使用此代码仅显示 UIStepper 控件的一部分

UIStepper *testStepper = [[UIStepper alloc]init];
[testStepper setFrame:CGRectMake(120, 220, 94, 27)];
testStepper.maximumValue = 5;
testStepper.minimumValue = 1;
testStepper.value = 1;

testStepper.layer.cornerRadius =3;
testStepper.layer.bounds= CGRectMake(0, 0, 47, 27);
testStepper.layer.masksToBounds=YES;
testStepper.layer.opacity = 1;

[self.view addSubview:testStepper];

但它并不完全有效。 UIStepper 现在只显示我想要的 UIStepper 的左侧(减号),但是当我按下减号的右侧时,它仍然添加一个值,当我按下左侧时它减去(我也想要左侧的东西)。 我做错了什么?

谢谢

【问题讨论】:

  • 为什么不用一个UIButton和一个标签,在action方法中处理最大值?

标签: objective-c xcode calayer uistepper


【解决方案1】:

您已将 ma​​kstoBounds 设置为 YES。基本上你隐藏 UIStepper:

testStepper.layer.bounds= CGRectMake(0, 0, 47, 27);
testStepper.layer.masksToBounds=YES;

如果您执行以下操作,您将看到整个 UIStepper。

testStepper.layer.bounds= CGRectMake(0, 0, 47, 27);
//testStepper.layer.masksToBounds=YES;

【讨论】:

  • 嗯,我认为这就是发生的情况:当我将边界设置为 (0,0,47,27) 时,UIStepper 只显示减号。但它也会缩放 UIStepper 中的按钮,因此创建的只有减号的 UIStepper 仍然有两半,左侧部分处理减法和右侧加法。是否可以消除这种行为?
  • 你为什么要使用边界?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-10
  • 1970-01-01
  • 2017-02-02
  • 2019-11-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多