zoukankan      html  css  js  c++  java
  • 第一个iOS App RadioStation

    同样来自Mitch, Bennett, Lees的教材,本人编译环境为Xcode 7

    新建IOS Project, SingleView Application。

    在Xcode环境中 - UI布局,添加UI对象,链接UI组件和UI对象。

    UI布局:通过拖曳右下角的UI组件到Main.Storyboard中的空白Layout中

       

    添加UI对象

    本例中在ViewController的实例变量中添加了 IBOutlet类的各个UI组件的对象 - 对应三个动态Label,一个Slider

    在类外面还定义了一个定义按钮动作的方法

    定义好了之后右击对应的标签,将Reference Outlets一项拉出一条直线和对应的Label对象相连:

    依次将要连接的动态标签,滑块,按钮都连接上。

    之后再ViewController.m的viewDidLoad方法中添加动作,为按钮和滑块的动作添加实现:

    //
    //  ViewController.m
    //  RadioStation
    //
    //  Created by 王 颖豪 on 2/25/16.
    //  Copyright © 2016 UTT Wangsta. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "RadioStation.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        myStation = [[RadioStation alloc] initWithName:@"STAR 94" atFrequency:88.3];
    
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    - (IBAction)sliderDidChange:(id)sender {
        [myStation setFrequency:setFrequency.value];
    }
    
    - (IBAction)buttonClick:(id)sender {
        [stationName setText:[myStation getName]];
        [stationFrequency setText:[NSString stringWithFormat:@"%.1f", [myStation getFrequency]]];
        if ([myStation getFrequency] >= [RadioStation minFMFrequency] &&
            [myStation getFrequency] <= [RadioStation maxFMFrequency]) {
            [stationBand setText:@"FM"];
        } else if( [myStation getFrequency] >= [RadioStation minAMFrequency] &&
                   [myStation getFrequency] <= [RadioStation maxAMFrequency]){
            [stationBand setText:@"AM"];
        } else {
            [stationBand setText:@"Invalid Band!"];
        }
    }
    
    @end
  • 相关阅读:
    驱动中回溯函数的调用关系
    CSI-MIPI学习笔记
    1920*1080分辨率和1080p,1080i的关系
    V4L2驱动内核文档翻译(一)
    signal()信号操作
    617. Merge Two Binary Trees
    Java中的集合
    Switch能否用string做参数
    Java面试题
    八种基本数据类型的大小,以及他们的封装类
  • 原文地址:https://www.cnblogs.com/wangsta/p/5218772.html
Copyright © 2011-2022 走看看