In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces iOS how to achieve the background sliding effect, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The details are as follows
The first step, in many APP, we can see those special effects gorgeous sliding option bar, so how can we achieve that effect simply and quickly?
# import @ interface ViewController: UIViewController {NSMutableArray * btnArray; NSMutableArray * titleArray;} @ property (nonatomic,strong) UIView * customView; @ property (nonatomic,strong) UIView * backView; @ property (nonatomic,strong) UIButton * myButton;-(void) myButtonClcik: (id) sender; @ end
Step 2: in our viewdidload method, or customize the interface elements that create us in a method. "I introduced the QuartzCore framework here to use its layer property."
# import "ViewController.h" # import @ interface ViewController () @ end @ implementation ViewController @ synthesize backView; @ synthesize myButton; / / the number of button displayed per row # define kSelectNum 6-(void) viewDidLoad {[super viewDidLoad]; / / Do any additional setup after loading the view, typically from a nib. / / create a background view and set the background color or picture customView = [[UIView alloc] initWithFrame:CGRectMake (20,100,900,60)]; customView.backgroundColor = [UIColor blackColor]; / / set the style of customView to fillet customView.layer.cornerRadius = 15.0f; customView.layer.masksToBounds = YES; / / customView add to the current main View [self.view addSubview:customView] / / create the background view of button backView = [UIView alloc] initWithFrame:CGRectMake (5,5,95,50)]; backView.backgroundColor = [UIColor blueColor]; / / set to fillet. In order to avoid overlapping display backView.layer.cornerRadius = 15.0f; backView.layer.masksToBounds = YES; / / add the backView view into customView [customView addSubview:backView]; / / create button, first of all, the number of button is not fixed, so we need to dynamically generate button / / create array and save button's title btnArray = [[NSMutableArray alloc] init] TitleArray = [[NSMutableArray alloc] initWithObjects:@ "blockbuster", @ "latest updates", @ "most popular", @ "American TV blockbuster", @ "Korean TV Channel", @ "Variety Entertainment", nil]; / / dynamically generate button for (int I = 0; I < kSelectNum; I + +) {myButton = [UIButton buttonWithType:UIButtonTypeCustom]; myButton.titleLabel.font = [UIFont boldSystemFontOfSize:20.0f] [myButton setTitle: [titleArray objectAtIndex:i] forState:UIControlStateNormal]; [myButton setTitleColor: [UIColor grayColor] forState:UIControlStateNormal]; [myButton setTitleColor: [UIColor whiteColor] forState:UIControlStateSelected]; [myButton setFrame:CGRectMake (I% (kSelectNum + 1) * 140mm 5,5,95,50)]; [myButton addTarget:self action:@selector (myButtonClcik:) forControlEvents:UIControlEventTouchUpInside]; myButton.tag = I; [btnArray addObject:myButton] [customView addSubview:myButton]; / / sets the color if (I = = 0) {myButton.selected = YES;}} of the default selected button.title
Step 3: we add button click events for button and set the background color sliding effect.
-(void) myButtonClcik: (id) sender {/ / NSString * selectedBtn = [NSString stringWithFormat:@ "% @", [titleArray objectAtIndex:button.tag]]; / / UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:selectedBtn delegate:self cancelButtonTitle:@ "OK" otherButtonTitles:nil, nil]; / / [alert show]; / / add animation over effects [UIView beginAnimations:@ "slowGlide" context:nil]; [UIView setAnimationDuration:0.3f] / / only one button UIButton * button = (UIButton *) sender; if (! button.selected) {for (UIButton * eachBtn in btnArray) {if (eachBtn.isSelected) {[eachBtn setSelected:NO];}} [button setSelected:YES] can be selected at a time. / / set which button is clicked, and the background of that button changes to the color of backView [backView setFrame:button.frame];} [UIView commitAnimations];}
Finally, we can adjust it according to the needs of our style.
Thank you for reading this article carefully. I hope the article "how to achieve the background sliding effect of iOS" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
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: 0
*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.