#import "AppDelegate.h"
#import "Denglu.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BOOL show=[[NSUserDefaults standardUserDefaults] objectForKey:@"showw"];
if(show==NO)
{
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"showw"];
Denglu *v1=[Denglu new];
self.window.rootViewController=v1;
}
else
{
ViewController *v2=[ViewController new];
self.window.rootViewController=v2;
}
return YES;
}
ViewCroller?
#import "ViewController.h"
#import "Wodeyinyue.h"
#import "Yinyueguan.h"
#import "FaxianViewController.h"
#import "Gengduo.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化4個控制器
Wodeyinyue *theWeixin = [[Wodeyinyue alloc]init];
theWeixin.title = @"我的音樂";
theWeixin.tabBarItem.image = [UIImage imageNamed:@"5"];
Yinyueguan *theCall = [[Yinyueguan alloc]init];
theCall.title = @"音樂館";
theCall.tabBarItem.image = [UIImage imageNamed:@"6"];
FaxianViewController *theSearch = [[FaxianViewController alloc]init];
theSearch.title = @"發(fā)現(xiàn)";
theSearch.tabBarItem.image = [UIImage imageNamed:@"7"];
Gengduo *theMy? =[[ Gengduo alloc]init];
theMy.title = @"更多";
theMy.tabBarItem.image = [UIImage imageNamed:@"8"];
//創(chuàng)建主視圖
//創(chuàng)建4個導(dǎo)航
UINavigationController *theWNav = [[UINavigationController alloc]initWithRootViewController:theWeixin];
UINavigationController *theCNav = [[UINavigationController alloc]initWithRootViewController:theCall];
UINavigationController *theSNav = [[UINavigationController alloc]initWithRootViewController:theSearch];
UINavigationController *theMNav = [[UINavigationController alloc]initWithRootViewController:theMy];
self.viewControllers = @[theWNav,theCNav, theSNav ,theMNav];
self.tabBarController.tabBar.tintColor = [UIColor redColor];
}
視圖1
// 類的延展@interface Wodeyinyue(){
//創(chuàng)建表格對象
UITableView? ? *theTableView;
//創(chuàng)建數(shù)組對象
NSArray? *theArr1;
NSArray *theArr3;
}
@end
@implementation Wodeyinyue
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBarController.tabBar.tintColor = [UIColor redColor];
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
//對表格和數(shù)組進行初始化
theTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
//添加表格協(xié)議
theTableView.delegate = self ;
theTableView.dataSource = self ;
//設(shè)置單元格顏色
theTableView.separatorColor = [UIColor blackColor];
//行高
theTableView.rowHeight = 60 ;
[self.view addSubview:theTableView];
theArr1 = [NSMutableArray arrayWithObjects:@"全部歌曲",@"下載歌曲",@"最近播放",@"iPod歌曲",nil];
theArr3 = @[[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"]];
#pragma -
#pragma mark -UITableViewDataSource
}? ? //設(shè)置分區(qū)的個數(shù)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return 1;
}
else if (section ==1) {
return 4 ;
}else if(section ==2) {
return 2;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"1508E"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"1508E"];
}
//添加箭頭符號
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
//第一個分區(qū)
if (indexPath.section == 0)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
cell.imageView.image = [UIImage imageNamed:@"10"];
cell.textLabel.text = @"未登錄";
cell.detailTextLabel.text = @"登陸后,和朋友們分享音樂";
UILabel *loginLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
loginLabel.textColor = [UIColor redColor];
loginLabel.text = @"登錄";
loginLabel.layer.borderColor = [[UIColor redColor] CGColor];
loginLabel.layer.borderWidth = 1.0;
loginLabel.layer.cornerRadius = 5.0;
loginLabel.textAlignment = NSTextAlignmentCenter;
cell.accessoryView = loginLabel;
}
else if(indexPath.section == 1)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
cell.imageView.image = [UIImage imageNamed:@"10"];
cell.textLabel.text = @"未登錄";
cell.detailTextLabel.text = @"登陸后,和朋友們分享音樂";
UILabel *loginLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
loginLabel.textColor = [UIColor redColor];
loginLabel.text = @"登錄";
loginLabel.layer.borderColor = [[UIColor redColor] CGColor];
loginLabel.layer.borderWidth = 1.0;
loginLabel.layer.cornerRadius = 5.0;
loginLabel.textAlignment = NSTextAlignmentCenter;
cell.accessoryView = loginLabel;? ? }
else
{
if (indexPath.row == 0)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = @"我的歌單";
cell.accessoryType =? UITableViewCellAccessoryDisclosureIndicator;
}
else
{
cell = [[UITableViewCell alloc] init];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 40)];
label.textAlignment = NSTextAlignmentCenter;
label.text = @"登錄賬戶,點擊紅心收藏喜歡的歌曲,\n實時同步到你的所有設(shè)備";
label.font = [UIFont systemFontOfSize:12];
label.numberOfLines = 2;
[cell addSubview:label];
}
}
return cell;
}
@end
輪播圖使用
#import "ViewController.h"#import "FirstViewController.h"@interface ViewController (){
UIScrollView *theScr;
NSArray *theArray;
UIPageControl *thePage;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化滾動視圖
theScr = [[UIScrollView alloc]initWithFrame:self.view.frame];
//設(shè)置代理
theScr.delegate = self;
//設(shè)置按頁滾動
theScr.pagingEnabled = YES;
//設(shè)置是否顯示滾動條
theScr.showsHorizontalScrollIndicator = NO;
//加載
[self.view addSubview:theScr];
theArray = @[@"4.png",@"5.jpg",@"6.jpg",@"7.jpg"];
CGFloat x = 0.0;
for (int i = 0 ; i<theArray.count;i++){
UIImageView *theImage = [[UIImageView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];
theImage.image = [UIImage imageNamed:theArray[i]];
x = x+self.view.frame.size.width;
[theScr addSubview:theImage];
if (i==theArray.count -1) {
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake((self.view.frame.size.width-100)/2, 550, 100, 40)];
[button setTitle:@"立即體驗" forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor colorWithRed:29/250.0 green:170/250.0 blue:230/250.0 alpha:1.0]];
[button addTarget:self action:@selector(tz) forControlEvents:UIControlEventTouchUpInside];
button.layer.cornerRadius = 10;
button.layer.masksToBounds = YES;
theImage.userInteractionEnabled=YES;
[theImage addSubview:button];
}
}
theScr.contentSize = CGSizeMake(x, self.view.frame.size.height);
//初始化一個分頁控制器的個數(shù)
thePage= [[UIPageControl alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-30, self.view.frame.size.height/5*4, 60, 20)];
//設(shè)置分頁的個數(shù)
thePage.numberOfPages = theArray.count;
//設(shè)置分頁控制器的顏色
thePage.pageIndicatorTintColor = [UIColor grayColor];
//設(shè)置分頁控制器選中時的顏色
thePage.currentPageIndicatorTintColor = [UIColor redColor];
//加載
[self.view addSubview: thePage];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
thePage.currentPage = theScr.contentOffset.x/self.view.frame.size.width;
}
-(void)tz
{
FirstViewController *jie1 = [FirstViewController new];
[self presentViewController:jie1 animated:YES completion:^{}];
}