简体   繁体   English

使用半透明分隔线、按钮大小和延迟色调自定义 UIStepper 时出现问题

[英]Problems customizing UIStepper with translucent divider, button sizes and deferring tint color

Having problems customizing the UIStepper control for my iOS app.为我的 iOS 应用程序自定义 UIStepper 控件时遇到问题。

So far I've been able to customize it to the point where the background and divider are translucent, as well as changed the increment and decrement images using the code below...到目前为止,我已经能够将其自定义为背景和分隔线是半透明的,并使用下面的代码更改了增量和减量图像......

func decorate(stepper: UIStepper) {
    let greyLeft   = UIImage(named: Assets.Button.leftGrey)
    let greenLeft  = UIImage(named: Assets.Button.leftGreen)
    let greyRight  = UIImage(named: Assets.Button.rightGrey)
    let greenRight = UIImage(named: Assets.Button.rightGreen)
    let blank      = UIImage(named: Assets.Button.translucent)
    let color      = UIColor(red:   147/255,
                             green: 148/255,
                             blue:   81/255,
                             alpha: 1.0)
    
    stepper.setDecrementImage(greenLeft,  for: .normal)
    stepper.setDecrementImage(greyLeft,   for: .disabled)
    stepper.setIncrementImage(greenRight, for: .normal)
    stepper.setIncrementImage(greyRight,  for: .disabled)
    stepper.setBackgroundImage(blank, for: .normal)
    stepper.setDividerImage(blank,
                            forLeftSegmentState: .normal,
                            rightSegmentState: .normal)
    stepper.tintColor = color
}

I have 3 problems though...虽然我有3个问题......

  1. While the divider is translucent in normal state, when I tap the control it seems to flash an image.虽然分隔线在正常 state 中是半透明的,但当我点击控件时,它似乎是 flash 图像。 I've tried using a second call to the "setDividerImage" method for all the other states available including "selected", "highlighted", "focused", "disabled", "application" and "reserved" but the flash is still there (see screenshot below).我尝试对所有其他可用状态(包括“选定”、“突出显示”、“聚焦”、“禁用”、“应用程序”和“保留”)使用“setDividerImage”方法的第二次调用,但 flash 仍然存在(见下面的截图)。 How do I replace that image with my own or prevent the flash?如何用我自己的图像替换该图像或防止 flash?

闪烁的分频器

  1. Even though I'm using two different images (same shape, different color) for the increment and decrement images their original colors are being overridden by the tint color.尽管我使用两个不同的图像(相同的形状,不同的颜色)作为增量和减量图像,但它们的原始 colors 被色调覆盖。 I think I can just cycle the tint color when it changes, but is it possible to defer the tint color so it doesn't override the image?我想我可以在它改变时循环色调颜色,但是是否可以推迟色调颜色以便它不会覆盖图像? Then I can avoid a solid color.然后我可以避免纯色。

  2. The images that I've got for the increment and decrement images are too small.我为增量和减量图像获得的图像太小了。 Can I adjust the size programmatically?我可以以编程方式调整大小吗? So I don't have to edit the images or go back to my graphic artist for larger ones.因此,我不必将图像或 go 编辑回我的图形艺术家以获得更大的图像。

Question #1 is my primary concern, because I think I can deal with #2 and #3 if needs be.问题 #1 是我最关心的问题,因为我认为如果需要我可以处理 #2 和 #3。 However, it would be great if I could at least get confirmation that the answers to those are "NO" if that's the case.但是,如果是这样的话,如果我至少可以确认这些答案是“否”,那就太好了。

Change this line:更改此行:

let blank = UIImage(named: Assets.Button.translucent)

to:至:

let blank = UIImage()

that should get rid of the highlighted separator.那应该摆脱突出显示的分隔符。

If your images are simple arrows, you could easily generate those via code "on-the-fly" with the desired colors, or use them as tint-able images.如果您的图像是简单的箭头,您可以使用所需的 colors 通过代码“即时”轻松生成这些箭头,或者将它们用作可着色图像。

If you load the images like this:如果您像这样加载图像:

let greyLeft   = UIImage(named: Assets.Button.leftGrey)?.withRenderingMode(.alwaysOriginal)
let greenLeft  = UIImage(named: Assets.Button.leftGreen)?.withRenderingMode(.alwaysOriginal)
let greyRight  = UIImage(named: Assets.Button.rightGrey)?.withRenderingMode(.alwaysOriginal)
let greenRight = UIImage(named: Assets.Button.rightGreen)?.withRenderingMode(.alwaysOriginal)

they shouldn't be affected by the tint color.它们不应该受到色调的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM