Saturday, January 28, 2017

iOS card view in uitable

iOS UITableview Card View


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MyCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.backgroundColor = [UIColor clearColor];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.layer.shouldRasterize = YES;
    cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    UIView *viewForCell=[[UIView alloc] initWithFrame:CGRectMake(0, 5, screenWidth-15, 95)];
    viewForCell.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    viewForCell.layer.shadowOpacity = 0.2f;
    viewForCell.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);
    viewForCell.layer.shadowRadius = 0.0f;
    viewForCell.backgroundColor = [UIColor whiteColor];
    viewForCell.layer.borderWidth=0.2f;
    viewForCell.layer.cornerRadius=5;
    viewForCell.layer.borderColor=[[UIColor lightGrayColor]CGColor];
    
    [cell.contentView addSubview:viewForCell];
    //Create UIElements here
return cell
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}

iOS custom alert

iOS custom alert 


-(void) customAlertForValidation: (NSString *) message
{
    UIView *viewAlert = [[UIView alloc] initWithFrame:CGRectMake(0, screenHeight-145, screenWidth, 50)];
    viewAlert.backgroundColor = [delegate navHeaderColor];
    [self.view addSubview:viewAlert];
    
    UILabel *lblMessage = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, screenWidth-20, 50)];
    lblMessage.textColor = [UIColor whiteColor];
    lblMessage.numberOfLines = 2;
    lblMessage.text = message;
    lblMessage.font = [UIFont fontWithName:fontName size:fontTextField];
    lblMessage.textAlignment = NSTextAlignmentCenter;
    [viewAlert addSubview:lblMessage];
    [UIView animateWithDuration:3.0
                     animations:^{viewAlert.alpha = 0.0;}
                     completion:^(BOOL finished){ [viewAlert removeFromSuperview]; }];

}

Thursday, January 12, 2017

Create label programmatically in swift

Create Label in swift programmatically 


         let colorLable = UILabel.init(frame: CGRect(x: 10, y: 10, width: screenWidth-20, height: 30));
        colorLable.backgroundColor = UIColor.lightGray;
        colorLable.text = colorArray [indexPath.row];
        colorLable.textColor = UIColor.green;
    colorLable.textAlignment = NSTextAlignment.center;
        cell.contentView.addSubview(colorLable);

How to create table view in swift 3.0 Pragmatically

How to create table view in swift 3.0 Pragmatically  


import UIKit
var studentTable:UITableView = UITableView();
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    let colorArray = ["Red", "Blue", "Green"];
    let screenWidth = UIScreen.main.bounds.width;
    let screenHeight = UIScreen.main.bounds.height;
    override func viewDidLoad() {
        super.viewDidLoad()
        studentTable = UITableView.init(frame: CGRect(x: 0, y: 50, width: screenWidth, height: screenHeight));
        studentTable.delegate = self;
        studentTable.dataSource = self;
        studentTable.backgroundColor = UIColor.white;
        self.view.addSubview(studentTable);
        // Do any additional setup after loading the view, typically from a nib.
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50;
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return colorArray.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "cell")
        
        let colorLable = UILabel.init(frame: CGRect(x: 10, y: 10, width: screenWidth-20, height: 30));
        colorLable.backgroundColor = UIColor.lightGray;
        colorLable.text = colorArray [indexPath.row];
        if indexPath.row == 0
        {
            colorLable.textColor = UIColor.red;
        }
        else if indexPath.row == 1
        {
            colorLable.textColor = UIColor.blue;
        }
        else
        {
            colorLable.textColor = UIColor.green;
        }
        colorLable.textAlignment = NSTextAlignment.center;
        cell.contentView.addSubview(colorLable);
        return cell;
        
    }

}

Upload UIImage as base64 String

Upload UIImage as Base64 String (Upload UIImage as string) //Select Pic From Camera or Gallery       @objc func btnPro...