Common custom control development set for iOS development series-custom drop-down list button control development
In actual development, we need to use the drop-down list many times. Let's implement it below.
The whc_combox.h header file is as follows:
//// WHC_ComboBox.h // WHC_ComboBox /// Created by Wu haichao on 15/4/2. /// # import
@ Interface WHC_ComboBox: UIButton @ end
The WHC_ComboBox.m source file is as follows:
//// WHC_ComboBox.m // WHC_ComboBox /// Created by Wu haichao on 15/4/2. //// # import "WHC_ComboBox.h" # define KWHC_PADING (5.0) // picture margin @ implementation WHC_ComboBox // load xib-(void) awakeFromNib {self. layer. borderColor = [UIColor blackColor]. CGColor; self. layer. borderWidth = 0.5;} // process the title area-(CGRect) titleRectForContentRect :( CGRect) contentRect {contentRect. origin. x = 1.0; return contentRect;} // process icon area-(CGRect) Align :( CGRect) contentRect {CGRect rc = CGRectZero; CGFloat width = CGRectGetHeight (contentRect)-2.0 * KWHC_PADING; rc. origin. x = CGRectGetWidth (contentRect)-width-KWHC_PADING; rc. origin. y = KWHC_PADING; rc. size. width = width; rc. size. height = width; return rc;} @ end