什么是方法“backgroundRect(forBounds:)"?UIButton 用于什么? [英] What is the method "backgroundRect(forBounds:)" of UIButton used for?
问题描述
我发现 UIButton
有一个 backgroundRect(forBounds:)
函数,但我不明白在哪里以及如何使用它.
我也无法理解如何使用 contentRect(forBounds:)
、titleRect(forContentRect:)
和 imageRect(forContentRect:)
方法.请解释一下.
默认情况下,backgroundRect(forBounds:)
返回与 bounds 相同的值代码>.但是,您可以在子类中覆盖它以防止覆盖您的自定义内容.
来自
I found out that UIButton
has a backgroundRect(forBounds:)
function, but I can not understand where and how can I use it.
I also cannot understand how can I use the contentRect(forBounds:)
, titleRect(forContentRect:)
and imageRect(forContentRect:)
methods. Please, explain me.
By default, backgroundRect(forBounds:)
returns the same value as bounds
. However, you can override it in a subclass to prevent drawing over your custom content.
From Apple Developer Documentation:
The default implementation of this method returns the value in the bounds parameter. This rectangle represents the area in which the button draws its standard background content. Subclasses that provide custom background adornments can override this method and return a modified bounds rectangle to prevent the button from drawing over any custom content.
contentRect(forBounds:)
returns the area that is used for displaying the title and the image of the button.
titleRect(forContentRect:)
and imageRect(forContentRect:)
return the rectangle of the title/image.
Here is some visual help for the return value of all four of these methods for a non-overridden, standard button:
这篇关于什么是方法“backgroundRect(forBounds:)"?UIButton 用于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!