`

ViewController添加button按钮解析。(翻译)

c 
阅读更多
<div class="iteye-blog-content-contain" style="font-size: 14px"></div>//  ViewController.m
//  Reservation software
//
//  Created by 张亚雄 on 15/6/2.
//  Copyright (c) 2015年 张亚雄. All rights reserved.
//

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

@end

@implementation ViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
   
   //   本项目。导航栏。 头文字
    self.navigationItem.title = @"订餐";
  //本项目,导航控制器背景颜色设置为黑色
    [self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
   //本项目,导航控制器标题文字颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
   
    //调取整体长宽高
    double width = self.view.frame.size.width;
    //设置button按钮
    [self create_button: width :@selector(order_button_pressed: ) :100 :@"帮订餐"];
    [self create_button: width :@selector(look_up_ordered_restaurant:) :150 :@"看订餐"];
    //设置button按钮颜色。
    UIViewController *viewController = [[UIViewController alloc]init];
    viewController.view.backgroundColor = [UIColor whiteColor];
   //push到子页页面
    [self.navigationController pushViewController:viewController animated:YES];}
  //设置各个button边框。
- (UIButton *)create_button :  (double)width :  (SEL)btn_pressed : (double)y :  (NSString * )title
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:self action:btn_pressed forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(width/8,y , 3*width/4, 35);
    button.layer.borderWidth = 1.0;
    button.layer.borderColor = [UIColor grayColor].CGColor;
    button.layer.cornerRadius = 10.0;
    [self.view addSubview:button];
    return button;
}
    //设置button源
-(void)order_button_pressed:(id)sender
{
    UIViewController *viewController = [[UIViewController alloc]init];
    viewController.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:viewController animated:YES];
}
//设置button源
- (void)look_up_ordered_restaurant : (id)sender
{
    UIViewController *viewController = [[UIViewController alloc]init];
    viewController.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:viewController animated:YES];
}

@end
  • 大小: 26.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics