iOS Common technology-Login screen

Source: Internet
Author: User
Tags uikit

//
SXTTextField.h
04-uitextfield Practice
//
Created by Andezhou on 16/1/8.
Copyright (c) 2016 Zhou Ande. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface Sxttextfield:uitextfield

Set the left picture name
@property (copy, nonatomic) NSString *leftimgname;

/**
* @brief Construction method
*
* @param frame position width high
* @param imgname
*
*/
-(Instancetype) initWithFrame: (CGRect) frame
Leftimgname: (NSString *) leftimgname;

@end
/************************************************/

//
Sxttextfield.m
04-uitextfield Practice
//
Created by Andezhou on 16/1/8.
Copyright (c) 2016 Zhou Ande. All rights reserved.
//

#import "SXTTextField.h"

@interface Sxttextfield ()

@property (Strong, nonatomic) Uiimageview *leftimageview;

@end

@implementation Sxttextfield

#pragma mark-
#pragma mark Lifecycle
-(Instancetype) initWithFrame: (CGRect) frame
Leftimgname: (NSString *) leftimgname
{
Self.leftimgname = Leftimgname;

return [self initwithframe:frame];
}

-(Instancetype) initWithFrame: (CGRect) frame
{
if (self = [Super Initwithframe:frame]) {
Set XX
Self.clearbuttonmode = Uitextfieldviewmodealways;
Second input erase content
self.clearsonbeginediting = YES;

return mode
Self.returnkeytype = Uireturnkeydone;

Set a background picture
Self.background = [UIImage imagenamed:@ "background"];

Set left View
Self.leftview = Self.leftimageview;
Set left view always exists
Self.leftviewmode = Uitextfieldviewmodealways;
}
return self;
}

#pragma mark-
#pragma Mark Init methods
-(Uiimageview *) Leftimageview
{
if (!_leftimageview) {
_leftimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (20, 4, 45, 36)];
_leftimageview.backgroundcolor = [Uicolor Clearcolor];
_leftimageview.contentmode = Uiviewcontentmodecenter;
}
return _leftimageview;
}

#pragma mark-
#pragma mark Set
-(void) Setleftimgname: (NSString *) leftimgname
{
_leftimgname = Leftimgname;

Show the picture on the Leftview
Self.leftImageView.image = [UIImage imagenamed:leftimgname];
}

@end
/***********************************************************/

//
Uicolor+extension.h
Nine Gongge
//
Created by Andezhou on 16/1/3.
COPYRIGHT©2016 year Zhou Ande. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface Uicolor (Extension)

+ (Uicolor *) colorwithhexstring: (NSString *) color;
+ (Uicolor *) colorwithhexstring: (NSString *) color alpha: (cgfloat) Alpha;


@end
/*************************************************************/

//
Uicolor+extension.m
Nine Gongge
//
Created by Andezhou on 16/1/3.
COPYRIGHT©2016 year Zhou Ande. All rights reserved.
//

#import "Uicolor+extension.h"
#define Default_void_color [Uicolor Whitecolor]

@implementation Uicolor (Extension)

#000000
+ (Uicolor *) colorwithhexstring: (NSString *) color alpha: (cgfloat) Alpha
{
NSString *cstring = [[Color Stringbytrimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]] Uppercasestring];

if ([cString length] < 6)
return default_void_color;
if ([CString hasprefix:@ "#"])
cString = [cString substringfromindex:1];
if ([cString length]! = 6)
return default_void_color;

Nsrange range;
range.location = 0;
Range.length = 2;
NSString *rstring = [cString substringwithrange:range];

Range.location = 2;
NSString *gstring = [cString substringwithrange:range];

Range.location = 4;
NSString *bstring = [cString substringwithrange:range];


unsigned int r, G, B;
[[Nsscanner scannerwithstring:rstring] scanhexint:&r];
[[Nsscanner scannerwithstring:gstring] scanhexint:&g];
[[Nsscanner scannerwithstring:bstring] scanhexint:&b];

return [Uicolor colorwithred: ((float) r/255.0f)
Green: ((float) g/255.0f)
Blue: ((float) b/255.0f)
Alpha:alpha];
}

+ (Uicolor *) colorwithhexstring: (NSString *) color
{
return [Uicolor Colorwithhexstring:color alpha:1.0];
}
@end
/**************************************************/

//
Viewcontroller.m
04-uitextfield Practice
//
Created by Andezhou on 16/1/8.
Copyright (c) 2016 Zhou Ande. All rights reserved.
//

#import "ViewController.h"
#import "Uicolor+extension.h"
#import "SXTTextField.h"

static Nsuinteger kmargin = 20;
#define Ktextfieldwidth [UIScreen mainscreen].bounds.size.width-2*kmargin

@interface Viewcontroller () <UITextFieldDelegate>

@property (Strong, nonatomic) Sxttextfield *usernametextfield, *passwordtextfield;
@property (Strong, nonatomic) UIButton *loginbtn;

@end

@implementation Viewcontroller


-(Sxttextfield *) Usernametextfield
{
if (!_usernametextfield) {
_usernametextfield = [[Sxttextfield alloc] Initwithframe:cgrectmake (Kmargin, N, Ktextfieldwidth, 44)];
_usernametextfield.delegate = self;
_usernametextfield.leftimgname = @ "UserName";
_usernametextfield.placeholder = @ "Please enter the phone number";
_usernametextfield.keyboardtype = Uikeyboardtypenumberpad;
}
return _usernametextfield;
}

-(Sxttextfield *) Passwordtextfield
{
if (!_passwordtextfield) {
CGRect frame = CGRectMake (Kmargin, Cgrectgetmaxy (_usernametextfield.frame) +, ktextfieldwidth, 44);
_passwordtextfield = [[Sxttextfield alloc] initwithframe:frame leftimgname:@ "password"];
_passwordtextfield.delegate = self;
Password mode
_passwordtextfield.securetextentry = YES;
_passwordtextfield.placeholder = @ "Please enter password";
}
return _passwordtextfield;
}

-(UIButton *) loginbtn
{
if (!_LOGINBTN) {
CGFloat pointy = Cgrectgetmaxy (_passwordtextfield.frame) + 50;
_LOGINBTN = [UIButton buttonwithtype:uibuttontypecustom];
_loginbtn.frame = CGRectMake (Kmargin, Pointy, ktextfieldwidth, 44);
[_loginbtn settitle:@ "Login" forstate:uicontrolstatenormal];
_loginbtn.titlelabel.font = [Uifont boldsystemfontofsize:16];
[_loginbtn setbackgroundimage:[uiimage imagenamed:@ "Beijing"] forstate:uicontrolstatenormal];
[_loginbtn addtarget:self Action: @selector (loginaction:) forcontrolevents:uicontroleventtouchupinside];
_loginbtn.layer.cornerradius = 4.0f;
_loginbtn.layer.maskstobounds = YES;
_loginbtn.enabled = NO;
}
return _loginbtn;
}

#pragma mark-
#pragma Mark Loginaction
-(void) Loginaction: (UIButton *) btn
{
NSLog (@ "username:%@ password:%@", _usernametextfield.text, _passwordtextfield.text);
}

#pragma mark-
#pragma Mark Uitextfielddelegate
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string
{
if ([_passwordtextfield.text isequaltostring:@ ""] | | [_usernametextfield.text isequaltostring:@ ""]) {
_loginbtn.enabled = NO;
}else{
_loginbtn.enabled = YES;
}

return YES;
}

-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
[Self.view Endediting:yes];
return YES;
}

#pragma mark-
#pragma mark Lifecycle
-(void) Viewdidload {
[Super Viewdidload];
Self.view.backgroundColor = [Uicolor colorwithhexstring:@ "#f7f8f3"];
[Self.view AddSubview:self.userNameTextField];
[Self.view AddSubview:self.passwordTextField];
[Self.view AddSubview:self.loginBtn];

}

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
[Self.view Endediting:yes];
}

-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}

@end
/***************************************************************/

iOS Common technology-Login screen

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.