欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS實現(xiàn)背景滑動效果

 更新時間:2022年03月21日 09:57:58   作者:yihaoxue  
這篇文章主要為大家詳細(xì)介紹了iOS實現(xiàn)背景滑動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了iOS實現(xiàn)背景滑動效果的具體代碼,供大家參考,具體內(nèi)容如下

1、在很多APP中,我們都可以看見那些特效絢麗的滑動選項條,那么如何才能夠簡單,快速的實現(xiàn)那樣的效果呢

#import <UIKit/UIKit.h> ?
??
@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 ?

第二步:在我們的額viewdidload方法中,或者自定義一個方法中創(chuàng)建我么的界面元素?!哆@里我引日了QuartzCore框架,是為了使用其layer屬性》

#import "ViewController.h" ?
#import <QuartzCore/QuartzCore.h> ?
??
@interface ViewController () ?
??
@end ?
??
@implementation ViewController ?
??
@synthesize customView; ?
@synthesize backView; ?
@synthesize myButton; ?
??
//每行顯示的button個數(shù) ?
#define kSelectNum 6 ?
??
- (void)viewDidLoad ?
{ ?
? ? [super viewDidLoad]; ?
? ? // Do any additional setup after loading the view, typically from a nib. ?
? ? ??
? ? //創(chuàng)建背景視圖,并設(shè)置背景顏色或者圖片 ?
? ? customView = [[UIView alloc]initWithFrame:CGRectMake(20, 100, 900, 60)]; ?
? ? customView.backgroundColor = [UIColor blackColor]; ?
? ? //設(shè)置customView的樣式,變?yōu)閳A角 ?
? ? customView.layer.cornerRadius = 15.0f; ?
? ? customView.layer.masksToBounds = YES; ?
? ? //將customView add 到當(dāng)前主View中 ?
? ? [self.view addSubview:customView]; ?
? ? ??
? ? //創(chuàng)建button的背景視圖 ?
? ? backView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, 95, 50)]; ?
? ? backView.backgroundColor = [UIColor blueColor]; ?
? ? //設(shè)置為圓角。以免造成重疊顯示 ?
? ? backView.layer.cornerRadius = 15.0f; ?
? ? backView.layer.masksToBounds = YES; ?
? ? //將backView視圖add到customView中 ?
? ? [customView addSubview:backView]; ?
? ? ??
? ? ??
? ? //創(chuàng)建button,首先button的個數(shù)是不固定的,因此我們需要動態(tài)的生成button ?
? ? //創(chuàng)建數(shù)組,保存button的title ?
? ? btnArray = [[NSMutableArray alloc]init]; ?
? ? titleArray = [[NSMutableArray alloc]initWithObjects:@"熱播大片",@"最新更新",@"最熱觀看",@"美劇大片",@"韓劇頻道",@"綜藝娛樂", nil]; ?
? ? //動態(tài)生成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)*140+5, 5, 95, 50)]; ?
? ? ? ? [myButton addTarget:self action:@selector(myButtonClcik:) forControlEvents:UIControlEventTouchUpInside]; ?
? ? ? ? myButton.tag = i; ?
? ? ? ? [btnArray addObject:myButton]; ?
? ? ? ? [customView addSubview:myButton]; ?
? ? ? ? ??
? ? ? ? //設(shè)置默認(rèn)選擇的button.title的顏色 ?
? ? ? ? if(i == 0){ ?
? ? ? ? ? ? myButton.selected = YES; ?
? ? ? ? } ?
? ? } ?
} ?

第三步:我們?yōu)閎utton添加按鈕點擊事件,同時設(shè)置背景色滑動特效。

- (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]; ?
? ? ??
? ? //添加動畫過度效果 ?
? ? [UIView beginAnimations:@"slowGlide" context:nil]; ?
? ? [UIView setAnimationDuration:0.3f]; ?
? ? ??
? ? //設(shè)置每次只能選擇一個button ?
? ? UIButton *button = (UIButton *)sender; ?
? ? if(!button.selected){ ?
? ? ? ? for (UIButton *eachBtn in btnArray) { ?
? ? ? ? ? ? if(eachBtn.isSelected){ ?
? ? ? ? ? ? ? ? [eachBtn setSelected:NO]; ?
? ? ? ? ? ? } ?
? ? ? ? } ?
? ? ? ? [button setSelected:YES]; ?
? ? ? ? ??
? ? ? ? //設(shè)置點擊那個按鈕,那個按鈕的背景改變?yōu)閎ackView的顏色 ?
? ? ? ? [backView setFrame:button.frame]; ?
? ? } ?
? ? [UIView commitAnimations]; ?
} ?

最后成型,我們就可以根據(jù)我們的樣式需要進(jìn)行調(diào)整了。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS點擊推送消息跳到應(yīng)用指定頁面方法

    iOS點擊推送消息跳到應(yīng)用指定頁面方法

    現(xiàn)在的推送用的越來越頻繁,幾乎每個應(yīng)用都開始用到了。這篇文章主要介紹了iOS點擊推送消息跳到應(yīng)用指定頁面方法,有需要的可以了解一下。
    2016-11-11
  • IOS CoreLocation實現(xiàn)系統(tǒng)自帶定位的方法

    IOS CoreLocation實現(xiàn)系統(tǒng)自帶定位的方法

    本篇文章主要介紹了IOS Core Location實現(xiàn)系統(tǒng)自帶定位的方法,非常具有實用價值,需要的朋友可以參考下。
    2017-02-02
  • iOS開發(fā)仿電商類APP首頁實例

    iOS開發(fā)仿電商類APP首頁實例

    本篇文章主要介紹了iOS開發(fā)仿電商類APP首頁實例,主要是利用ui布局,具有一定的參考價值,有需要的可以了解一下。
    2016-11-11
  • IOS 字符串常用處理詳細(xì)介紹

    IOS 字符串常用處理詳細(xì)介紹

    這篇文章主要介紹了IOS 字符串常用處理詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Swift實現(xiàn)iOS應(yīng)用中短信驗證碼倒計時功能的實例分享

    Swift實現(xiàn)iOS應(yīng)用中短信驗證碼倒計時功能的實例分享

    這篇文章主要介紹了Swift實現(xiàn)iOS應(yīng)用中短信驗證碼倒計時功能的實例分享,開啟和關(guān)閉倒計時功能的步驟實現(xiàn)比較關(guān)鍵,需要的朋友可以參考下
    2016-04-04
  • iOS中正則表達(dá)式的運用示例代碼

    iOS中正則表達(dá)式的運用示例代碼

    正則表達(dá)式(廣為所知的“regex”)是一個字符串或一個字符序列來說明一種模式,把它作為一個搜索字符串-非常強(qiáng)大!下面這篇文章主要給大家介紹了關(guān)于iOS中正則表達(dá)式運用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。
    2017-09-09
  • IOS中內(nèi)存管理那些事

    IOS中內(nèi)存管理那些事

    這篇文章主要介紹了IOS中內(nèi)存管理那些事的相關(guān)資料,需要的朋友可以參考下
    2015-11-11
  • iOS實現(xiàn)無限循環(huán)滾動的TableView實戰(zhàn)教程

    iOS實現(xiàn)無限循環(huán)滾動的TableView實戰(zhàn)教程

    這篇文章主要給大家介紹了關(guān)于iOS實現(xiàn)無限循環(huán)滾動的TableView的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-05-05
  • iOS實現(xiàn)聯(lián)系人列表功能

    iOS實現(xiàn)聯(lián)系人列表功能

    這篇文章主要為大家詳細(xì)介紹了iOS實現(xiàn)聯(lián)系人列表功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • iOS Xcode8更新后輸出log日志關(guān)閉的方法

    iOS Xcode8更新后輸出log日志關(guān)閉的方法

    今天剛把xcode更新到了xcode8,運行發(fā)現(xiàn)好多l(xiāng)og輸出,怎么關(guān)閉呢,不是很清楚,通過查閱相關(guān)資料順利關(guān)掉這些log日志,下面小編把方法共享下,需要的朋友參考下
    2016-09-09

最新評論