Custom Control Development set for iOS development series-custom single-choice button or multiple-choice button control development
In our actual development, when we perform login or registration, we often need to select a Protocol. At this time, we need to use the CheckBox button. the CheckBox is a pc or android control that does not exist in ios, so we need to customize it.
The WHC_RadioButton.h header file is as follows:
/// WHC_RadioButton.h // CTBMobileBank // Created by Wu haichao on 15/4/1. // # import
# Define KWHC_IMAGE_SIZE (15.0) // Icon size @ interface WHC_RadioButton: UIButton @ end
The WHC_RadioButton.m source file is as follows:
/// WHC_RadioButton.m // CTBMobileBank // Created by Wu haichao on 15/4/1. /// # import "WHC_RadioButton.h" @ implementation WHC_RadioButton // processing button title area-(CGRect) titleRectForContentRect :( CGRect) contentRect {contentRect. origin. x = KWHC_IMAGE_SIZE; return contentRect;} // processing icon area-(CGRect) imageRectForContentRect :( CGRect) contentRect {CGRect rect = CGRectZero; rect. origin. x = 0.0; rect. origin. y = (CGRectGetHeight (self. bounds)-KWHC_IMAGE_SIZE)/2.0; rect. size. height = KWHC_IMAGE_SIZE; rect. size. width = KWHC_IMAGE_SIZE; return rect;} @ end