Ios button Customization

Source: Internet
Author: User

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

 
 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.