The main work of the project, to be able to press through the button to flip the previous and next photo on the line view function. The project is a bit simple, but it is a necessary process for learning. The collation and reference of learning.
Main Purpose:
1) familiar with the use of the 3 major controls and rules
2) familiar with the programming method of 3 big control
3) familiar with ISO development skills
The following is the source of today's learning content, this part of the source of the implementation of a bit wordy, later will be changed to, and then use the plist way and the way to apply the array, to simplify the implementation of the picture display method.
#import "ViewController.h"
@interface Viewcontroller ()
@property (nonatomic, strong) UILabel *ilabel;
@property (nonatomic, strong) Uiimageview *iimage;
@property (nonatomic, strong) UILabel *ideslabel;
@property (nonatomic, strong) UIButton *leftbutton;
@property (nonatomic, strong) UIButton *rightbutton;
@property (nonatomic, assign) int index;
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
/* Label */
Self.ilabel = [[UILabel alloc]initwithframe:cgrectmake (0, Self.view.frame.size.width, 40)];
Self.iLabel.textAlignment = Nstextalignmentcenter;
[Self.view Addsubview:_ilabel];
/* Show Pictures */
CGFloat image_w = 300;
CGFloat image_h = 300;
CGFloat image_x = (self.view.frame.size.width-image_w) *0.5;
CGFloat image_y = Cgrectgetmaxy (self.iLabel.frame) + 20;
Self.iimage = [[Uiimageview alloc]initwithframe:cgrectmake (image_x, image_y, Image_w, Image_h)];
Self.iImage.image = [UIImage imagenamed:@ "Biaoqingdi"];
[Self.view Addsubview:_iimage];
/* Show Left and right buttons */
Self.leftbutton = [[UIButton alloc]initwithframe:cgrectmake (0, 0, 40, 40)];
Self.leftButton.center = Cgpointmake (Cgrectgetminx (self.iImage.frame) * 0.5, (Cgrectgetminy (self.iImage.frame) + self.iimage.frame.size.height* 0.5));
[_leftbutton setimage:[uiimage imagenamed:@ "Left_normal"] forstate:uicontrolstatenormal];
[_leftbutton setimage:[uiimage imagenamed:@ "left_highlighted"] forstate:uicontrolstatehighlighted];
_leftbutton.tag =-1;
[Self.view Addsubview:_leftbutton];
[_leftbutton addtarget:self Action: @selector (Leftaction) forcontrolevents:uicontroleventtouchupinside];
Self.rightbutton = [[UIButton alloc]initwithframe:cgrectmake (0, 0, 40, 40)];
Self.rightButton.center = Cgpointmake ((Cgrectgetmaxx (self.iImage.frame) + self.leftbutton.center.x), (cgrectgetminy (self.iImage.frame) + self.iimage.frame.size.height* 0.5));
[_rightbutton setimage:[uiimage imagenamed:@ "Right_normal"] forstate:uicontrolstatenormal];
_rightbutton.tag = 1;
[_rightbutton setimage:[uiimage imagenamed:@ "right_highlighted"] forstate:uicontrolstatehighlighted];
[Self.view Addsubview:_rightbutton];
[_rightbutton addtarget:self Action: @selector (Rightaction) forcontrolevents:uicontroleventtouchupinside];
/* Description Content */
Self.ideslabel = [[UILabel alloc] Initwithframe:cgrectmake (0, Cgrectgetmaxy (self.iImage.frame) + 30, Self.view.frame.size.width, 20)];
Self.idesLabel.textAlignment = Nstextalignmentcenter;
[Self.view Addsubview:_ideslabel];
[Self buttonaction:nil];
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
-(void) Buttonaction:(UIButton *) Button
{
NSLog (@ "%s", __func__);
Self.index + = (int) Button.tag;
/* Display Index */
Self.iLabel.text = [NSString stringwithformat:@ "%d/%d", Self.index + 1, 5];
Switch (SELF.INDEX)
{
Case 0:
Self.iImage.image = [UIImage imagenamed:@ "Biaoqingdi"];
Self.idesLabel.text = @ "Expression Emperor";
Break
Case 1:
Self.iImage.image = [UIImage imagenamed:@ "Bingli"];
Self.idesLabel.text = @ "Case table";
Break
Case 2:
Self.iImage.image = [UIImage imagenamed:@ "Chiniupa"];
Self.idesLabel.text = @ "Eat steak";
Break
Case 3:
Self.iImage.image = [UIImage imagenamed:@ "Danteng"];
Self.idesLabel.text = @ "Egg hurts";
Break
Case 4:
Self.iImage.image = [UIImage imagenamed:@ "Wangba"];
Self.idesLabel.text = @ "Wang Ba";
Break
Default
Break
}
}
-(void) leftaction
{
[Self buttonaction: _leftbutton];
_leftbutton.enabled = (Self.index! = 0);
_rightbutton.enabled = (Self.index! = 4);
}
-(void) rightaction
{
[Self Buttonaction:_rightbutton];
_leftbutton.enabled = (Self.index! = 0);
_rightbutton.enabled = (Self.index! = 4);
}
@end
Summarize:
1) If it is a few buttons, you can use the +-1 way tag to simplify and clear.
2) UIButton and other control applications are not the same
3) in the code to think of the code reuse how to deal with can make the code more simple!
This article is from the "Lelon iOS Development path" blog, so be sure to keep this source http://51851851888888.blog.51cto.com/7026900/1750435
ISO Development Learning Path--first--Image display production (1)