//
Viewcontroller.m
Ui-no-9
//
Created by Bruce on 15/7/23.
Copyright (c) 2015 Bruce. All rights reserved.
//
#import "ViewController.h"
@interface Viewcontroller ()
{
UIView *bgview;
Uiimageview *animationview;
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Bgview = [[UIView alloc]initwithframe:self.view.frame];
[Self.view Addsubview:bgview];
Nsmutablearray *images = [Nsmutablearray array];
for (int i=1; i<=6; i++) {
[Images addobject:[uiimage imagenamed:[nsstring stringwithformat:@ "niao2-%d (dragged). Tiff", I]];
}
Animationview = [[Uiimageview alloc]initwithframe:cgrectmake (0, 0, 100, 100)];
Animationview.animationimages = images;
Animationview.animationrepeatcount =-1;
Animationview.animationduration = 3;
[Self.view Addsubview:animationview];
1, segmented Select control when using multiple buttons you can choose to use the segmented selection control
2. Switch button
3, sliding bar
Today, it's all about Uicontrol. The sub-categories include the previously learned buttons
1. Segment Selection Control
Segment selection control you need to give him an array of headings when you start the initialization.
Uisegmentedcontrol *segment = [[Uisegmentedcontrol alloc]initwithitems:@[@ "Entertainment", @ "military", @ "technology"];
Segment.frame = CGRectMake (100, 100, 200, 40);
Sets whether to remember the previous button
Segment.momentary = YES;
[Segment Addtarget:self Action: @selector (segmentaction:) forcontrolevents:uicontroleventvaluechanged];
[Self.view addsubview:segment];
Switch button
The switch button generally needs to record the user set status 1, can use the interface provided by the background to set the switch button switches (can be synchronized between different devices state (information)) 2, save the settings locally
Uiswitch *switchbutton = [[Uiswitch alloc]initwithframe:cgrectmake (100, 200, 50, 40)];
[Switchbutton addtarget:self Action: @selector (switchaction:) forcontrolevents:uicontroleventvaluechanged];
Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];
Set the default state of switch
Switchbutton.on = [Userdefaults boolforkey:@ "IsOn"];
Sets the color of the track when the switch button is open
Switchbutton.ontintcolor = [Uicolor Redcolor];
Set the track color when the switch button is off
Switchbutton.tintcolor = [Uicolor Greencolor];
Sets the color of the switch button small circle
Switchbutton.thumbtintcolor = [Uicolor Yellowcolor];
[Self.view Addsubview:switchbutton];
Sliding Bar
UISlider *slider = [[UISlider alloc]initwithframe:cgrectmake (100, 300, 200, 10)];
[Slider addtarget:self action: @selector (slideraction:) forcontrolevents:uicontroleventvaluechanged];
Set the minimum value of the slider bar
Slider.minimumvalue = 1;
Set the maximum value of the slider bar
Slider.maximumvalue = 10;
Set the default position of the slider bar
Slider.value = 1;
Sets the track color for the minimum value of the slider bar
Slider.minimumtracktintcolor = [Uicolor Redcolor];
Track color of slider Max
Slider.maximumtracktintcolor = [Uicolor Purplecolor];
The color of the small circle
Slider.thumbtintcolor = [Uicolor Yellowcolor];
[Self.view Addsubview:slider];
}
Trigger when the finger touches the screen
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
if ([[Nsuserdefaults standarduserdefaults] boolforkey:@ "IsOn"]!=no) {
Get Touch events
Uitouch *touch = [touches anyobject];
Get the point of touch
Cgpoint touchPoint = [Touch LocationInView:self.view];
When the animation does not execute, call the inside method
if (animationview.isanimating! = YES) {
Animationview.alpha = 1.0;
Animationview.center = TouchPoint;
[Animationview startanimating];
}
}
}
The finger moves on the screen to trigger
-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) event
{
if ([[Nsuserdefaults standarduserdefaults] boolforkey:@ "IsOn"]! = NO) {
Get Touch events
Uitouch *touch = [touches anyobject];
Get the point of touch
Cgpoint touchPoint = [Touch LocationInView:self.view];
Animationview.center = TouchPoint;
}
}
Trigger when finger leaves the screen (touch end)
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) event
{
if ([[Nsuserdefaults standarduserdefaults] boolforkey:@ "IsOn"]! = NO) {
[UIView Animatewithduration:2 animations:^{
Animationview.alpha = 0.0;
} completion:^ (BOOL finished) {
[Animationview stopanimating];
}];
}
}
-(void) Slideraction: (UISlider *) sender
{
NSLog (@ "%0.2f", Sender.value);
Animationview.animationduration = Sender.value;
}
-(void) Switchaction: (Uiswitch *) sender
{
NSLog (@ "%d", Sender.ison);
Nsuserdefaults *userdefaults = [Nsuserdefaults standarduserdefaults];
[Userdefaults setBool:sender.isOn forkey:@ "IsOn"];
[Userdefaults Synchronize];
}
-(void) Segmentaction: (Uisegmentedcontrol *) sender
{
NSLog (@ "%ld", Sender.selectedsegmentindex);
Switch (sender.selectedsegmentindex) {
Case 0:
Bgview.backgroundcolor = [Uicolor Browncolor];
Break
Case 1:
Bgview.backgroundcolor = [Uicolor Whitecolor];
Break
Case 2:
Bgview.backgroundcolor = [Uicolor Lightgraycolor];
Break
Default
Break
}
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
@end
Control controls (Sliders, segment selection controls, switch buttons)