#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 = @"发现";
theSearch.tabBarItem.image = [UIImage imageNamed:@"7"];
Gengduo *theMy =[[ Gengduo alloc]init];
theMy.title = @"更多";
theMy.tabBarItem.image = [UIImage imageNamed:@"8"];
//创建主视图
//创建4个导航
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(){
//创建表格对象
UITableView *theTableView;
//创建数组对象
NSArray *theArr1;
NSArray *theArr3;
}
@end
@implementation Wodeyinyue
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBarController.tabBar.tintColor = [UIColor redColor];
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
//对表格和数组进行初始化
theTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
//添加表格协议
theTableView.delegate = self ;
theTableView.dataSource = self ;
//设置单元格颜色
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
} //设置分区的个数
- (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;
//第一个分区
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实时同步到你的所有设备";
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];
//设置代理
theScr.delegate = self;
//设置按页滚动
theScr.pagingEnabled = YES;
//设置是否显示滚动条
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);
//初始化一个分页控制器的个数
thePage= [[UIPageControl alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-30, self.view.frame.size.height/5*4, 60, 20)];
//设置分页的个数
thePage.numberOfPages = theArray.count;
//设置分页控制器的颜色
thePage.pageIndicatorTintColor = [UIColor grayColor];
//设置分页控制器选中时的颜色
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:^{}];
}