You can use the subclass Button to customize your own button class.
During subclass, You can reload the following methods, which return the CGRect structure and specify the boundary of each component of the button.
Note: Do not call these methods directly. These methods are written to the system call.
// These return the rectangle for the background (assumes bounds), the content (image + title) and for the image and title separately. the content rect is calculated based
// On the title and image size and padding and then adjusted based on the control content alignment. there are no draw methods since the contents
// Are rendered in separate subviews (UIImageView, UILabel)
-(CGRect) backgroundRectForBounds :( CGRect) bounds; // return the background boundary (image + title)
-(CGRect) contentRectForBounds :( CGRect) bounds ;//
-(CGRect) titleRectForContentRect :( CGRect) contentRect; // return the title boundary.
-(CGRect) imageRectForContentRect :( CGRect) contentRect; // returns the image boundary.
Example:
# Define BACK_BOUNDS_W 54.0
# Define BACK_BOUNDS_H 22.0
-(CGRect) backgroundRectForBounds :( CGRect) bounds
{
Return CGRectMake (bounds. size. width-BACK_BOUNDS_W)/2,
-BACK_BOUNDS_H,
BACK_BOUNDS_W,
BACK_BOUNDS_H );
}
For example, the Option Button in defines the position of the image and text