Sunday, August 25, 2013

Using Colourful Texts in Default Navigation Bar in iOS

It is a very common problem for iOS Developers that we want to use Colourful texts in the Default Navigation Bar but do not know how to do it. Today I am showing you how to use colourful text in the default Navigation Bar. We have to do it programmatically.



- (void)viewDidLoad
{
    [super viewDidLoad];
        
    self.title=@"You Tube Vedio";
    UILabel *titleView = (UILabel *)self.navigationItem.titleView;
    if (!titleView) {
        titleView = [[UILabel alloc] initWithFrame:CGRectZero];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.font = [UIFont boldSystemFontOfSize:20.0];
        titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        
        titleView.textColor = [UIColor redColor]; // Change to desired color
        
        self.navigationItem.titleView = titleView;
        [titleView release];
    }
    titleView.text = self.title;
    [titleView sizeToFit];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
}





I hope it will be helpful to you . 

Happy Coding 
Mahboob

Wednesday, August 21, 2013

Displaying Youtube Videos in iOS App

Now a day youtube is a very famous website for videos not only for entertainment but also for tutorials. If you want to play youtube video using iOS app you have to use Web view  and write the simple code in viewDidLoad method given below:


- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *html = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {    background-color: transparent;\
    color: white; \
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <iframe class=\"youtube-player\" width=\"300\" height=\"300\" src=\"http://www.youtube.com/embed/5hyy2JfuXko\" frameborder=\"0\" allowfullscreen=\"true\"></iframe>\
    </body></html>";
    
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:CGRectMake(10.0, 80.0, 300.0, 300.0)];
    videoView.backgroundColor=[UIColor blackColor];
    videoView.scrollView.bounces=NO;
    [videoView loadHTMLString:html baseURL:nil];
    [self.view addSubview:videoView];
}

Then you can run the app and play youtube videos :

Create Grid Like xl sheet using iOS App


In this section I would like to discuss how to create gird like xl sheet using iOS Application. Well we have create it in a custom way .

  • At first we will take an image view for the header of the grid. We will set the header image in the imageView. 
  • Then we will use textBox and set the textBox programatically in effective way . 
  • We have to keep in mind that in which position we are setting the header image. According to the header image we will take the dimension and set the textBox programatically. 
  • Another thing is the grid size is dynamic according to the user choice. 
The source code is given below:

headerImageView=[[UIImageView alloc]initWithFrame:CGRectMake(055076881)];
    headerImageView.image=[UIImage imageNamed:@"R_11.png"];
    [scrollView addSubview:headerImageView];
    int x=0;
    int y=633;
    int count2=[self getCFLNo];
    NSLog(@"cflNo : %d",count2);
    
    for(int p=1 ;p<=count2;)
    {
        x=0;
        blankCellImageView=[[UIImageView alloc]initWithFrame:CGRectMake(x, y, 24050)];
        blankCellImageView.image=[UIImage imageNamed:@"blankCell.png"];
        blankCellImageView.alpha=0.8;
        [scrollView addSubview:blankCellImageView];
        x=x+110;
        // y=y+52;
        large15WTextBField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large15WTextBField.font=font;
        large15WTextBField.backgroundColor=[UIColor whiteColor];
        large15WTextBField.layer.borderColor=[[UIColor blackColor]CGColor];
        large15WTextBField.layer.borderWidth2.0f;
        [large15WTextBField resignFirstResponder];
        large15WTextBField.delegate=self;
        // serialNumberTextField.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large15WTextBField];
        x=x+110;
        //y=y+52;
        small15WBTextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        small15WBTextField.font=font;
        small15WBTextField.backgroundColor=[UIColor whiteColor];
        small15WBTextField.layer.borderColor=[[UIColor blackColor]CGColor];
        small15WBTextField.layer.borderWidth2.0f;
        [small15WBTextField resignFirstResponder];
        // roomNameTextField.textAlignment=UITextAlignmentCenter;
        small15WBTextField.delegate=self;
        [scrollView addSubview:small15WBTextField];
        x=x+110;
        // y=y+52;
        large20WBTextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large20WBTextField.font=font;
        large20WBTextField.backgroundColor=[UIColor whiteColor];
        large20WBTextField.layer.borderColor=[[UIColor blackColor]CGColor];
        large20WBTextField.layer.borderWidth2.0f;
        [large20WBTextField resignFirstResponder];
        large20WBTextField.delegate=self;
        //  masterDeviceTextField.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large20WBTextField];
        x=x+110;
        //y=y+52;
        large15WTextEField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large15WTextEField.font=font;
        large15WTextEField.backgroundColor=[UIColor whiteColor];
        large15WTextEField.layer.borderColor=[[UIColor blackColor]CGColor];
        large15WTextEField.layer.borderWidth2.0f;
        [large15WTextEField resignFirstResponder];
        large15WTextEField.delegate=self;
        //   slaveDeviceTextField1.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large15WTextEField];
        x=x+110;
        // y=y+52;
        small15WETextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        small15WETextField.font=font;
        small15WETextField.backgroundColor=[UIColor whiteColor];
        small15WETextField.layer.borderColor=[[UIColor blackColor]CGColor];
        small15WETextField.layer.borderWidth2.0f;
        [small15WETextField resignFirstResponder];
        small15WETextField.delegate=self;
        //  slaveDeviceTextField2.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:small15WETextField];
        x=x+110;
        NSLog(@"x: %d",x);
        //  y=y+52;
        large20WETextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large20WETextField.font=font;
        large20WETextField.backgroundColor=[UIColor whiteColor];
        large20WETextField.layer.borderColor=[[UIColor blackColor]CGColor];
        large20WETextField.layer.borderWidth2.0f;
        [large20WETextField resignFirstResponder];
        large20WETextField.delegate=self;
        //    slaveDeviceTextField3.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large20WETextField];
        if(x==660)
        {
            y=y+52;
        }
        
        p++;
        
    }

For example the user wants to use 6 columns in the grid , then the grid will be this.....