Wednesday, August 10, 2016

iOS Set Image from URL

We can set image to image view from url by converting content of url in NSData as follow.

in viewDidLoad() add following code

 UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
    NSString *strUrl = @"http://www.freedigitalphotos.net/images/img/homepage/87357.jpg";
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl]];
    img.image = [UIImage imageWithData:imageData];

    [self.view addSubview:img];

Also add Following lines to info.plist file for resolve 
Transport security has blocked a cleartext HTTP


NSAppTransportSecurity
NSAllowsArbitraryLoads
     

Radio Button In iOS

Radio Button In iOS

For Radio button demo we used

Four Labels and two buttons

Label 1 - Radio button demo text
Label 2 - Select gender text
Label 3 - Male Text
Label 4 - Female Text

Two button for radio selection functionality.
Drag all labels and buttons to view controller at storyboard.

Create iboutlet to h file as follow
#import
#import "TestDelegate.h"
@interface ViewController : UIViewController<TestDelegate>
@property (weak, nonatomic) IBOutlet UILabel *lblValue;

@property (weak, nonatomic) IBOutlet UISlider *slider;

- (IBAction)sliderValueChanged:(id)sender;

- (IBAction)btnMale:(id)sender;
- (IBAction)btnFemale:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *ioMale;
@property (weak, nonatomic) IBOutlet UIButton *ioFemale;

@end

In .m File do following functionality

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (IBAction)btnMale:(id)sender {
   [self.ioMale setBackgroundImage:[UIImage imageNamed:@"radio_checked.png"] forState:UIControlStateNormal];
    [self.ioFemale setBackgroundImage:[UIImage imageNamed:@"radio_uncheck.png"] forState:UIControlStateNormal];
    
}

- (IBAction)btnFemale:(id)sender {[self.ioMale setBackgroundImage:[UIImage imageNamed:@"radio_uncheck.png"] forState:UIControlStateNormal];
    [self.ioFemale setBackgroundImage:[UIImage imageNamed:@"radio_checked.png"] forState:UIControlStateNormal];
}

#pragma mark - Sample protocol delegate
-(void)processCompleted{
   
}
@end

Upload UIImage as base64 String

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