All posts by azmaltech

About azmaltech

https://bd.linkedin.com/in/azmaltech https://www.facebook.com/azmaltech

TextField and button in objective-C

//
// ViewController.h
// helloWorld2
//
// Created by USSLPS11 on 12/10/16.
// Copyright © 2016 USSLPS11. All rights reserved.
//



#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic, strong) UITextField* userName;
@property (nonatomic, strong) UITextField* userPassword;

@property (nonatomic, copy) NSString* userText;
@property (nonatomic, copy) NSString* userPass;

@end
// azmalhossain
///
// ViewController.m
// TextFieldSample
//
// Created by USSLPS1 on 12/10/16.
// Copyright © 2016 USSLPS1. All rights reserved.
// azmal

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
}

- (void)viewDidLoad {
 [super viewDidLoad];
 
 self.userName = [[UITextField alloc] init]; // initional system
 self.userName.frame = CGRectMake(30, 100, 300, 44); // frame around size
 self.userName.delegate = self; // to attach delegate rule
 self.userName.placeholder = @"Email"; // for placeholder preview
 self.userName.backgroundColor = [UIColor greenColor];
 self.userName.returnKeyType = UIReturnKeyNext; // to change done button in keyboard
 [self.view addSubview:self.userName]; // add subview
 
 
 self.userPassword = [[UITextField alloc] init];
 self.userPassword.frame = CGRectMake(30, 150, 300, 44);
 self.userPassword.delegate = self;
 self.userPassword.placeholder = @"Password";
 self.userPassword.backgroundColor = [UIColor greenColor];
 self.userPassword.returnKeyType = UIReturnKeyDone;
 self.userPassword.secureTextEntry = YES; // to show star symble instant of number
 [self.view addSubview:self.userPassword];
 
 // beign to button works
 UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
 button.frame = CGRectMake(130, 200, 100, 18);
 [button setTitle:@"Press Me" forState:UIControlStateNormal]; // for title
 [button addTarget:self action:@selector(pressMeAction:) forControlEvents:UIControlEventTouchUpInside];
 [self.view addSubview:button]; // for new view on prime view
}

- (void)pressMeAction:(UIButton*) sender {
 [self.view endEditing:YES];
 [self showAuthentication];
}

#pragma mark --
#pragma mark -- UITextField delegate

- (void)textFieldDidBeginEditing:(UITextField *)textField {
 if (textField == self.userName) {
 self.userText = @"";
 } else if (textField == self.userPassword) {
 self.userPass = @"";
 }
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
 if (textField == self.userName) {
 self.userText = textField.text;
 } else if (textField == self.userPassword) {
 self.userPass = textField.text;
 }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField { // sumbit botton
 if (textField == self.userName) {
 [textField resignFirstResponder];
 [self.userPassword becomeFirstResponder]; // atomatic moving to next after completing tying in textfield
 } else if (textField == self.userPassword) {
 [textField resignFirstResponder];
 [self showAuthentication];
 }
 return YES;
}

- (void)showAuthentication {
 if (self.userText.length > 0 && self.userPass.length > 0) { // to check the password and id name
 
 NSString* detailMessage = [NSString stringWithFormat:@"Your User Name = %@, \n and Password = %@", self.userText, self.userPass];
 
 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Authentication Success" message:detailMessage preferredStyle:UIAlertControllerStyleAlert];
 
 UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
 [alertController addAction:ok];
 
 [self presentViewController:alertController animated:YES completion:nil];
 }
}

@end
Advertisements

Table View Part-3

import UIKit
class ViewController: UIViewController, UITableViewDataSource {
let dailyTask = [ "Check all windows", "check all doors", "check temperature of freezer","check the mailBox at at the end fo the lane","empty trash containers","if freezing, check water popes outside"]
 let weeklyTasks = ["check inside all unoccupied cabins", "run all faucets for 30 seconds","Walk the perimeter of property", "Arrange for dumpster pickup"]
 let twoWeekTasks = ["Run test on security alarm","check all motion detectors","Test smoke alarms"]
 func numberOfSections(in tableView: UITableView) -> Int {
 return 3 // declared 3 array formar
 }
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 switch section {
 case 0:
 return dailyTask.count
 case 1:
 return weeklyTasks.count
 case 2:
 return twoWeekTasks.count
 default:
 return 0
 }
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 var currentTask : String
 switch indexPath.section {
 case 0:
 currentTask = dailyTask[indexPath.row]
 case 1 :
 currentTask = weeklyTasks[indexPath.row]
 case 2:
 currentTask = twoWeekTasks[indexPath.row]
 default:
 currentTask = ""
 }
 cell.textLabel!.text = currentTask
 return cell
 }
 func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
 switch section {
 case 0:
 return "Dail Tasks:"
 case 1:
 return "Weekly Tasks"
 case 2:
 return "Every Two Weeks"
 default:
 return "This Should Not Be Here"
 }
 }
 
 
 override func viewDidLoad() {
 super.viewDidLoad()

 // Do any additional setup after loading the view.
 }

 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 // Dispose of any resources that can be recreated.
 }

}

View

create a customView Subclass at first
click File from Manu -> New -> File
and flow downCode

import UIKit

@IBDesignable

class customView: UIView {

  override func draw(_ rect: CGRect) {  

// indicate for borderline

    layer.borderWidth = 10.0

  }
}

put view by dragging from object library, 
select view and works in pin.
put 20 spacing to nearest neighbor.
unselect constraint to margins
in update frames select items of new constraints.
add 4 constraints

note : if you find some red color  view
resolve auto layout issues
click -> all views in view controller -> Update Frames
Note: if find something wrong 
click -> all views in view controller -> Clear Constraints

in Identity inspector, class change to customView
Note : if you can change anything
click -> product from manu -> Clean 
again click -> product -> build

screen-shot-2016-12-01-at-7-42-53-am

Table View with Sections and Headings


import UIKit

class ViewController: UIViewController, UITableViewDataSource {
 let dailyTask = ["check all windows","check all doors","check temperature of freezer","check the mailbox at the end of the lane","Empty trash containers","if freezing, check water pines outside"]
 let weeklyTasks = ["check inside all unoccupied cabins","Run all faucets for 30 seconds","Arraunge for dumpster pickup"]
 let twoWeekTasks = ["run test on security alarm","check all motion detectors","Test smoke a alarm"]
 func numberOfSections(in tableView: UITableView) -> Int {
 return 3 // how many section have
 }
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 switch section {
 case 0:
 return dailyTask.count
 case 1:
 return weeklyTasks.count
 case 2:
 return twoWeekTasks.count
 default:
 return 0
 }
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 var currentTask: String
 switch indexPath.section {
 case 0:
 currentTask = dailyTask[indexPath.row]
 case 1:
 currentTask = weeklyTasks[indexPath.row]
 case 2:
 currentTask = twoWeekTasks[indexPath.row]
 default:
 currentTask = ""
 }
 cell.textLabel!.text = currentTask
 return cell
 }
 func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
 switch section {
 case 0:
 return "Daily Tasks"
 case 1:
 return "Weekly Tasks"
 case 2:
 return "Every Two Weeks"
 default:
 return "This Should Not Be Here" }
 }

 override func viewDidLoad() {
 super.viewDidLoad()
 // Do any additional setup after loading the view, typically from a nib.
 }

 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 // Dispose of any resources that can be recreated.
 }

}

Table View with Number List

// Created by Mohammad Azmal Hossain on 11/22/16.
// Copyright © 2016 Mohammad Azmal Hossain. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UITableViewDataSource {

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 return 10
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 cell.textLabel!.text = "this is row \(indexPath.row)"
 return cell
 }
 
 override func viewDidLoad() {
 super.viewDidLoad()
 // Do any additional setup after loading the view, typically from a nib.
 }

 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 // Dispose of any resources that can be recreated.
 }


}