4.5 " 人人”简单项目

#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [self createViewController];
    return YES;
}

- (void)createViewController {

    ViewController * rootVC = [[ViewController alloc] init];
    
    //导航控制器的根视图控制器
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:rootVC];
    
    [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"header_bg"] forBarMetrics:UIBarMetricsDefault];
    
    nav.navigationBar.translucent = YES;
    
    //全屏的window
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    //window的根视图控制器
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];

}
#import "ViewController.h"
#import "ADButton.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //定制导航栏元素
    [self makeNavigationItems];
    //添加背景图片
    UIImageView * backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    
    backgroundImageView.image = [UIImage imageNamed:@"rr_main_background@2x"];
    [self.view addSubview:backgroundImageView];
    //添加副按钮
    [self addSubButtons];
    
    [self addMainButtons];
    
    // Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - 定制导航栏元素
- (void)makeNavigationItems {
    //中间部分:titleView
    //左右侧:UIBarButtonItem : UIBarItem
    
    UIImageView * titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_title"]];
    //直接再导航栏的中间设置一个图片标题
    self.navigationItem.titleView = titleImageView;
    
    //左右侧:  1.官方样式  2.只有文本  3.只有图片  4.任意自定制视图
    
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"main_left_nav"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"main_right_nav"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.rightBarButtonItem = rightItem;

}


- (void)addSubButtons {

    //照片  状态   报到
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 30)];
    
    view.backgroundColor = [UIColor whiteColor];
    
    NSArray * title = @[@"照片",@"状态",@"报到"];
    
    NSArray * imageNames = @[@"rr_pub_takephoto@2x",@"rr_pub_status@2x",@"rr_pub_checkin@2x"];
    
    for (int i = 0; i < [imageNames count]; i++) {
        UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(i * [UIScreen mainScreen].bounds.size.width / 3, 0, [UIScreen mainScreen].bounds.size.width / 3, 30)];
        [button setTitle:title[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        [button setImage:[UIImage imageNamed:imageNames[i]] forState:UIControlStateNormal];
        
        [view addSubview:button];
        
        //调整图标和标题的位置
        //标题的偏移量  尽量用负数
//        button.titleEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>);
//        button.imageEdgeInsets =        
    }    
    [self.view addSubview:view];
}
#pragma mark - 添加主按钮
- (void)addMainButtons {

    //1.点击无效果 HighLighted状态
    //2、无法绑定事件
    ADButton * button = [[ADButton alloc] initWithFrame:CGRectMake(100, 140, 60, 80)];
    
    button.image = [UIImage imageNamed:@"xiangce"];
    button.title = @"相册";

    [self.view addSubview:button];
}
" 人人”简单项目.png

你可能感兴趣的:(4.5 " 人人”简单项目)