In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "IOS how to customize the UIButton nine grid effect", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "IOS how to customize the UIButton nine grid effect" this article.
Mainly using UIButton to elaborate
The actual list is not complicated and can be completed in two or three steps:
Define width and height (self.view)
# define SCREEN_WIDTH [UIScreen mainScreen] .bounds.size.width # define SCREEN_HEIGHT [UIScreen mainScreen] .bounds.size.heigh # define JHRGB (rmae GLO b) [UIColor colorWithRed: (rMab 255.0) green: (gUnip 255.0) blue: (bmax 255.0) alpha:1.0] # define JHRandomColor JHRGB (arc4random_uniform (255), arc4random_uniform (255), arc4random_uniform (255))
Second, define the words and pictures of Jiugong grid
@ property (nonatomic, strong) NSArray * titlesArr;@property (nonatomic, strong) UILabel * numberLab;@property (nonatomic, strong) NSArray * titleimg;- (NSArray *) titlesArr {if (! _ titlesArr) {_ titlesArr = @ [@ "Home Page", @ "purchase", @ "Article", @ "Community", @ "Service", @ "scan", @ "location", @ "after sales", @ "order"];} return _ titlesArr }-(NSArray *) titleimg {if (! _ titleimg) {_ titleimg = @ [@ "me", @ "msg", @ "meg", @ "1", @ "2", @ "3", @ "me", @ "2", @ "3"];} return _ titleimg;}
3. Cycle out 9 pieces of UIBtton data and adjust the related styles dynamically
-(void) setButton {NSInteger totalLoc = 3 self.titlesArr.count; btn / a list of three numbers CGFloat W = 50 NSInteger bank / width CGFloat H = W X bank / height CGFloat margin= (self.view.frame.size.width-totalLoc * W) / (totalLoc+1); for (NSInteger I = 0; I < self.titlesArr.count; iota +) {/ / cyclic body UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom]; / / definition of button btn.frame = CGRectMake (100,100,80,80) / / button size [btn setTitle:self.titlesArr [I] forState:UIControlStateNormal]; / / dynamically set button text [btn setBackgroundImage: [UIImage imageNamed: self.titleimg [I]] forState:UIControlStateNormal]; / / dynamically set picture [btn setTitleColor: [UIColor darkGrayColor] forState:0]; / / text color [btn setImageEdgeInsets:UIEdgeInsetsMake (5,25,45,25)]; / / Image size [btn setTitleEdgeInsets:UIEdgeInsetsMake (80,0,5,0)] / / location of the text / / btn.backgroundColor = [UIColor blueColor]; / * calculate frame*/ NSInteger row = I / totalLoc;// line number NSInteger loc = I% totalLoc;// column number / / 0 row; btn.frame = CGRectMake (X, Y, W, H) * loc; CGFloat Y = margin + (margin + H) / / set the tag value (tag here, just so that each click of button has a different animation effect) btn.tag = I; [btn addTarget:self action:@selector (clickBtn:) forControlEvents:UIControlEventTouchUpInside]; [self.lgView.imgview addSubview:btn];}}
IV. Event monitoring when clicking a button
-(void) clickBtn: (UIButton *) btn {NSString * stringInt = [NSString stringWithFormat:@ "% ld", (long) btn.tag]; btn.layer.transform = CATransform3DMakeScale (0.5*arc4random_uniform ([stringInt floatValue]), 0.5*arc4random_uniform ([stringInt floatValue]), 1); self.numberLab.text = btn.titleLabel.text; NSLog (@ "% @ wo dian ji l:", stringInt); [UIView animateWithDuration:0.5 animations: ^ {btn.layer.transform = CATransform3DMakeScale (1,1,1);}] }
These are all the contents of this article entitled "how to customize the UIButton Nine Palace effect by IOS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 227
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.