IOS學(xué)習(xí)—控件的綜合練習(xí)
來源:易賢網(wǎng) 閱讀:1303 次 日期:2015-04-21 13:49:01
溫馨提示:易賢網(wǎng)小編為您整理了“IOS學(xué)習(xí)—控件的綜合練習(xí)”,方便廣大網(wǎng)友查閱!

//

// ViewController.h

// 圖片瀏覽器

//

// Created by on 15/4/14.

// Copyright (c) 2015年 apple. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (weak, nonatomic) IBOutlet UILabel *imageValue;

@property (weak, nonatomic) IBOutlet UILabel *imageDesc;

@property (weak, nonatomic) IBOutlet UIView *settingView;

- (IBAction)valueChange:(UISlider *)sender;

- (IBAction)settingButton;

- (IBAction)darkModel:(UISwitch *)sender;

- (IBAction)imageSize:(UISlider *)sender;

@end

//

// ViewController.m

// 圖片瀏覽器

//

// Created by on 15/4/14.

// Copyright (c) 2015年 apple. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

{

NSArray *_imageMess;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 要訪問項(xiàng)目中的所有資源用mainBundle

NSBundle *bundle = [NSBundle mainBundle];

NSString *filePath = [bundle pathForResource:@"imageMessages" ofType:@"plist"];

// 讀取文件要傳入絕對(duì)路徑

_imageMess = [NSArray arrayWithContentsOfFile:filePath];

NSDictionary *dic = _imageMess[0];

NSString *imageName = [dic objectForKey:@"icon"];

_imageView.image = [UIImage imageNamed:imageName];

NSString *imageMessage = [dic objectForKey:@"title"];

_imageDesc.text = imageMessage;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (IBAction)valueChange:(UISlider *)sender {

// 這里的%.f即為不保留小數(shù)位,四舍五入

// NSString *imageName = [NSString stringWithFormat:@"%.f", sender.value];

NSDictionary *dic = _imageMess[(int)sender.value - 1];

NSString *imageName = [dic objectForKey:@"icon"];

_imageView.image = [UIImage imageNamed:imageName];

NSString *imageValue = [NSString stringWithFormat:@"%.f/%.f", sender.value, sender.maximumValue];

_imageValue.text = imageValue;

NSString *imageMessage = [dic objectForKey:@"title"];

_imageDesc.text = imageMessage;

}

#pragma mark 注意這里的寫法,如果信息處理不同的話,多用這種方式重構(gòu)代碼

-(void)animationCustom:(void (^)())block {

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.35];

block();

[UIView commitAnimations];

}

- (IBAction)settingButton {

CGFloat viewHeight = _settingView.frame.size.height;

[self animationCustom:^{

if (_settingView.frame.origin.y == self.view.frame.size.height) {

CGRect frame = _settingView.frame;

frame.origin.y -= viewHeight;

_settingView.frame = frame;

} else {

CGRect frame = _settingView.frame;

frame.origin.y += viewHeight;

_settingView.frame = frame;

}

}];

}

- (IBAction)darkModel:(UISwitch *)sender {

if (sender.on) {

self.view.backgroundColor = [UIColor darkGrayColor];

} else {

self.view.backgroundColor = [UIColor whiteColor];

}

}

- (IBAction)imageSize:(UISlider *)sender {

_imageView.transform = CGAffineTransformMakeScale(sender.value, sender.value);

}

@end

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看技術(shù)文章
易賢網(wǎng)手機(jī)網(wǎng)站地址:IOS學(xué)習(xí)—控件的綜合練習(xí)
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)