Button action not working [duplicate] - ios

This question already has an answer here:
UIButton action not working ios
(1 answer)
Closed 6 years ago.
UITextField *tf2 = [[UITextField alloc] initWithFrame:CGRectMake(10, tf1.frame.origin.y+55, 200, 30)];
tf2.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
//tf.font = [UIFont fontWithName:#"Helvetica-Bold" size:25];
tf2.backgroundColor=[UIColor whiteColor];
tf2.borderStyle=UITextBorderStyleLine;
tf2.placeholder=#"Capture Invoice";
tf2.textAlignment=UITextAlignmentCenter;
UIButton *invoiceBtn=[[UIButton alloc]initWithFrame:CGRectMake(250, tf1.frame.origin.y+55,50,30)];
UIImage *buttonImage = [UIImage imageNamed:#"camera-app-icon_1x.png"];
[invoiceBtn setImage:buttonImage forState:UIControlStateNormal];
[invoiceBtn addTarget:self action:#selector(invoiceClicked:) forControlEvents:UIControlEventTouchUpInside];
view1 = [[UIView alloc] initWithFrame:CGRectMake(0,270, 100, 40)];
[view1 addSubview:tf2];
[view1 addSubview:invoiceBtn];

firstly increase frame size of your view1 and add this line to your code
[self.view addSubView: view1];
like this:
UITextField *tf2 = [[UITextField alloc] initWithFrame:CGRectMake(10, 55, 200, 30)];
tf2.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
//[tf2 setPlaceholder:#"hello"];
//tf.font = [UIFont fontWithName:#"Helvetica-Bold" size:25];
tf2.backgroundColor=[UIColor whiteColor];
tf2.borderStyle=UITextBorderStyleLine;
tf2.placeholder=#"Capture Invoice";
tf2.textAlignment=UITextAlignmentCenter;
UIButton *invoiceBtn=[[UIButton alloc]initWithFrame:CGRectMake(25, 100,50,30)];
//UIImage *buttonImage = [UIImage imageNamed:#"camera-app-icon_1x.png"];
[invoiceBtn setBackgroundColor:[UIColor blueColor]];
[invoiceBtn setTitle:#"Click" forState:UIControlStateNormal];
//[invoiceBtn setImage:buttonImage forState:UIControlStateNormal];
[invoiceBtn addTarget:self action:#selector(invoiceClicked:) forControlEvents:UIControlEventTouchUpInside];
UIView* view1 = [[UIView alloc] initWithFrame:CGRectMake(0,170, 300, 400)];
[view1 setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:view1];
[view1 addSubview:tf2];
[view1 addSubview:invoiceBtn];
it gives output in simulator as and button is clickable

UITextField *tf2 = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 200, 30)];
tf2.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
//tf.font = [UIFont fontWithName:#"Helvetica-Bold" size:25];
tf2.backgroundColor=[UIColor whiteColor];
tf2.borderStyle=UITextBorderStyleLine;
tf2.placeholder=#"Capture Invoice";
tf2.textAlignment=UITextAlignmentCenter;
UIButton *invoiceBtn=[[UIButton alloc]initWithFrame:CGRectMake(250, tf2.frame.origin.y+55,50,30)];
UIImage *buttonImage = [UIImage imageNamed:#"camera-app-icon_1x.png"];
[invoiceBtn setImage:buttonImage forState:UIControlStateNormal];
[invoiceBtn addTarget:self action:#selector(invoiceClicked:) forControlEvents:UIControlEventTouchUpInside];
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0,270, 100, 40)];
[view1 addSubview:tf2];
[view1 addSubview:invoiceBtn];
[self.view addSubview:view1];

Apply like this,
UIButton * invoiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:#"camera-app-icon_1x.png"];
[invoiceBtn setImage:buttonImage forState:UIControlStateNormal];
[invoiceBtn addTarget:self
action:#selector(invoiceClicked:) forControlEvents:UIControlEventTouchUpInside];
invoiceBtn.frame = CGRectMake(250, tf2.frame.origin.y+55,50,30);
[view1 addSubview: invoiceBtn];
Then create action like,
- (void)invoiceClicked:(UIButton*)button
{
NSLog(#"Button clicked.");
}
Hope this works for you :)

Related

UINavigationController centered button using obj-c

I'm trying to add a centered button in my navbar header, confused as to how I can do it
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *meImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:#"%#/me.png", kSelfBundlePath]];
UIBarButtonItem *meButton = [[UIBarButtonItem alloc] initWithImage:meImage style:UIBarButtonItemStylePlain target:self action:#selector(twitterButton)];
[self.titleView //i read this can be used to like set it but i havent been able to figure it out
help would be appreciated, pretty new
check this code
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
container.backgroundColor = [UIColor clearColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 44, 44)];
[btn setBackgroundImage:[UIImage imageNamed:#"button0.png"] forState:UIControlStateNormal];
[btn addTarget:self action:#selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[btn setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
//add your spacer images and button1 and button2...
self.navigationItem.titleView = container;
You can try like this way
UIView *topView = [[UIView alloc]initWithFrame:CGRectZero];
UIButton * button = [[UIButton alloc]initWithFrame:CGRectZero];
[button addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Title here" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button sizeToFit];
[topView addSubview:button];
[topView sizeToFit];
self.navigationItem.titleView = topView;
-(void)buttonAction:(Id) sender {
NSLog(#"button clicked");
}
I think its pretty straight, you can use titleView property of UINavigationItem :
-(void)addCenterButton {
UIImage *meImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:#"%#/me.png", kSelfBundlePath]];
UIButton *button = [[UIButton alloc] initWithFrame::CGRectMake(0, 0, 40, 20)];
[button setImage:meImage forState:UIControlStateNormal];
[button addTarget:self action:#selector(twitterButton) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = button;
}

mulpitle UILabel in Navigation titleView [duplicate]

I am developing one application for iphone and in that i have some issues regarding adding more then one UILabel in navigation bar at a specific position.
What i want is in following images
in above image there is one backbar button and one imageview as shown with arrow-mark. Other then that all white box is for difrent UILabels to show in navigation bar.
There is only one UIImageView in the navigation bar and one left bar button. Now problem is that i don't know how to add multiple UILabel in navigation bar at a specific position.
Till now what i have worked is to add only button and UIImageView with the right bar button array or left bar button array, but that only add items in sequnce.
So can anyone please guide me that how can anyone add UILabels or any other item at a specific position..
you can add Multiple UIlabel or Image as look like bellow image:-
this can do using bellow code you can change Label and imageView frame and put as your requirement
- (void)viewDidLoad
{
UIView *btn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
UILabel *label;
label = [[UILabel alloc] initWithFrame:CGRectMake(5, 25, 200, 16)];
label.tag = 1;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.text = #"My first lable";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 200, 16)];
label.tag = 2;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor whiteColor];
label.text = #"second line";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
imgviw.backgroundColor = [UIColor blackColor];
imgviw.image=[UIImage imageNamed:#"a59117c2eb511d911cbf62cf97a34d56.png"];
[btn addSubview:imgviw];
self.navigationItem.titleView = btn;
}
You can add subviews directly to the navigationBar -
UINavigationBar *navBar = navController.navigationBar;
[navBar addSubview: yourLabel];
yourLabel frame origin will be relative to the navigation bar
Try this code
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
buttonContainer.backgroundColor = [UIColor clearColor];
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setFrame: CGRectMake(160, 7 , 40, 30)];
[button0 setTitle:#"Sort" forState:UIControlStateNormal];
button0.titleLabel.font = [UIFont fontWithName:#"Helvetica" size:12];
[button0 setBackgroundImage:[UIImage imageNamed:#"Btn_Sort_Btn_Sort_Places.png"] forState:UIControlStateNormal];
[button0 addTarget:self action:#selector(sortAction) forControlEvents:UIControlEventTouchUpInside];
[button0 setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
self.navigationItem.titleView = buttonContainer;
UILabel *lbl_title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0 , 140, 40)];
lbl_title.text = str_HeaderTitle;
lbl_title.textColor = [UIColor whiteColor];
lbl_title.font = [UIFont fontWithName:#"Helvetica-Bold" size:16];
lbl_title.backgroundColor = [UIColor clearColor];
lbl_title.textAlignment = NSTextAlignmentCenter;
[buttonContainer addSubview:lbl_title];
You can set an arbitrary view instead of a view controller's title:
myViewController.navigationItem.titleView = someView;
Note that most likely the view's frame will be restricted to make room for leftBarButtonItem and rightBarButtonItem.
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(50, 2, 20, 15)];
[label setBackgroundColor:[UIColor greenColor]];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(40, 20, 150, 10)];
[imgView setBackgroundColor:[UIColor redColor]];
[[self.navigationController navigationBar] addSubview:label];
[self.navigationController.navigationBar addSubview:imgView];
Have a look at this piece of code. With some modifications it should solve your problem:
UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imageButton setFrame:CGRectMake(15, 0, 57, 44)];
[imageButton setBackgroundImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 0, 250, 44)];
[titleLabel setText:#"some title"];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[self.navigationController.navigationBar addSubview:imageButton];
[self.navigationController.navigationBar addSubview:titleLabel];
Just modify the values in the CGRectMake() to fit your needs.

iOS- Objective C - Show a view on ipad only but hide on iPhone

I need a solution for the problem described below..
I have a scenario where a view needs to be shown only on ipad but it needs to be hidden on iphone. The way the view is built is as follows:
The below code shows the view on ipad. I want to hide this view when loaded on iphone.
How can this be achieved?
(void)viewDidLoad
{
[super viewDidLoad];
gotQuoteList = NO;
isExpanded = NO;
heightOfUploadManager = 282;
freqQuotesArray = [[NSMutableArray alloc] init];
selectedCheckboxes = [[NSMutableDictionary alloc] init];
serviceConfig_G_Obj = [[ServiceConfig alloc] init];
cacheManager_G_Obj = [[CacheManager alloc] init];
[self.view setBackgroundColor: [[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[self observeRotationChanges];
uploadMngrView = [[UIView alloc] init];
[self setUploadManagerFrame];
[uploadMngrView setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
uploadMngrView.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadMngrView.layer.borderWidth = 1.0;
[self.view addSubview:uploadMngrView];
UIView *titleLblBgView = [[UIView alloc] init];
[titleLblBgView setFrame:CGRectMake(0, 40, 512, 1)];
[titleLblBgView setBackgroundColor:[self colorWithHexString:#"C7C7C7"]];
[uploadMngrView addSubview:titleLblBgView];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 1, 512-21, 38)];
[titleLabel setText:#"Upload Document"];
[titleLabel setTextAlignment:NSTextAlignmentLeft];
[titleLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[titleLabel setTextColor:[self colorWithHexString:#"656565"]];
[titleLabel setFont:[UIFont fontWithName:#"Arial" size:21]];
[uploadMngrView addSubview:titleLabel];
UILabel *fileLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, 141, 34)];
[fileLabel setText:#"File"];
[fileLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[fileLabel setTextColor:[self colorWithHexString:#"656565"]];
[fileLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:fileLabel];
UILabel *fileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 60, 329, 34)];
[fileNameLabel setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]];
[fileNameLabel setTextColor:[self colorWithHexString:#"656565"]];
[fileNameLabel setText:[NSString stringWithFormat:#" %#",[[self getFileName] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[fileNameLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
fileNameLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
fileNameLabel.layer.borderWidth = 1.0;
[uploadMngrView addSubview:fileNameLabel];
UILabel *destinationLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 114, 141, 34)];
[destinationLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationLabel setText:#"Destination"];
[destinationLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[destinationLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:destinationLabel];
UILabel *destinationNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 114, 329, 34)];
destinationNameLabel.tag = 1;
UITapGestureRecognizer *worksaceRBTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapRadioBtnLabelWithGesture:)];
worksaceRBTapGestureRecognizer.numberOfTapsRequired = 1;
[destinationNameLabel setUserInteractionEnabled:YES];
[destinationNameLabel addGestureRecognizer:worksaceRBTapGestureRecognizer];
destinationNameLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
destinationNameLabel.layer.borderWidth = 1.0;
[destinationNameLabel setText:#" My Workspace"];
[destinationNameLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]]; [destinationNameLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationNameLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:destinationNameLabel];
myWorkspaceRadioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
myWorkspaceRadioBtn.tag = 1;
[myWorkspaceRadioBtn setImage:[UIImage imageNamed:#"radiobtn_off.png"] forState:UIControlStateNormal];
[myWorkspaceRadioBtn setImage:[UIImage imageNamed:#"radiobtn_on.png"] forState:UIControlStateSelected];
[myWorkspaceRadioBtn setFrame:CGRectMake(166, 121, 26, 22)];
myWorkspaceRadioBtn.selected=YES;
[myWorkspaceRadioBtn addTarget:self action:#selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:myWorkspaceRadioBtn];
UILabel *destinationQuoteLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 147, 329, 34)];
destinationQuoteLabel.tag = 2;
UITapGestureRecognizer *quotelistRBTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapRadioBtnLabelWithGesture:)];
quotelistRBTapGestureRecognizer.numberOfTapsRequired = 1;
[destinationQuoteLabel setUserInteractionEnabled:YES];
[destinationQuoteLabel addGestureRecognizer:quotelistRBTapGestureRecognizer];
destinationQuoteLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
destinationQuoteLabel.layer.borderWidth = 1.0;
[destinationQuoteLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationQuoteLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[destinationQuoteLabel setText:#" Link to selected quote"];
[destinationQuoteLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]];
[uploadMngrView addSubview:destinationQuoteLabel];
quoteListRadioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
quoteListRadioBtn.tag = 2;
[quoteListRadioBtn setImage:[UIImage imageNamed:#"radiobtn_off.png"] forState:UIControlStateNormal];
[quoteListRadioBtn setImage:[UIImage imageNamed:#"radiobtn_on.png"] forState:UIControlStateSelected];
[quoteListRadioBtn setFrame:CGRectMake(166, 152, 26, 22)];
[quoteListRadioBtn addTarget:self action:#selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:quoteListRadioBtn];
[self fillQuoteListScrollView];
lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 202, 512, 1)];
lineView.backgroundColor = [self colorWithHexString:#"C7C7C7"];
[uploadMngrView addSubview:lineView];
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton setFrame:CGRectMake(20, 222, 231, 40)];
[cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[cancelButton setTitleColor:[self colorWithHexString:#"656565"] forState:UIControlStateNormal];
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
CAGradientLayer *cancelBtnGradient = [CAGradientLayer layer];
cancelBtnGradient.frame = cancelButton.bounds;
cancelBtnGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:238.0/255.0f green:238.0/255.0f blue:238.0/255.0f alpha:1.0f] CGColor], nil];
[cancelButton.layer insertSublayer:cancelBtnGradient atIndex:0];
cancelButton.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
cancelButton.layer.borderWidth = 1.0;
[cancelButton addTarget:self action:#selector(cancelUpload) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:cancelButton];
uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[uploadButton setFrame:CGRectMake(261, 222, 231, 40)];
[uploadButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[uploadButton setTitleColor:[self colorWithHexString:#"55A0B9"] forState:UIControlStateNormal];
[uploadButton setTitle:#"Upload" forState:UIControlStateNormal];
CAGradientLayer *uploadBtnGradient = [CAGradientLayer layer];
uploadBtnGradient.frame = uploadButton.bounds;
uploadBtnGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:238.0/255.0f green:238.0/255.0f blue:238.0/255.0f alpha:1.0f] CGColor], nil];
[uploadButton.layer insertSublayer:uploadBtnGradient atIndex:0];
uploadButton.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadButton.layer.borderWidth = 1.0;
[uploadButton addTarget:self action:#selector(uploadDoc) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:uploadButton];
}
You can do this like this,
uploadMngrView = [[UIView alloc] init];
[self setUploadManagerFrame];
[uploadMngrView setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
uploadMngrView.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadMngrView.layer.borderWidth = 1.0;
if ([UIDevice currentDevice].userInterfaceIdom == UIUserInterfaceIdoniPad) {
[self.view addSubview:uploadMngrView];
}
HTH, Enjoy Coding !!
As your setting up the views programatically, you something like this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Create the view only for ipad
self.someView = [[UIView alloc] initWithFrame:someFrame];
//Or set the view hidden just on ipad
self.someView.hidden = YES;
//Or set the view a different frame on ipad
self.someView.frame = CGRectMake(x,y,width,height);
}
else
{
//Do some non ipad layout stuff here
}

Warning A long-running Parse operation is being executed on the main thread? [duplicate]

This question already has answers here:
A long-running Parse operation is being executed on the main thread
(4 answers)
Closed 7 years ago.
A long-running Parse operation is being executed on the main thread is happening on this part of code from below, i can't seem to figure out how to rid the error. Any help on how to get rid of warning.
PFFile *image = (PFFile *)[wallObject objectForKey:KEY_IMAGE];
UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]];
userImage.frame = CGRectMake(0, 65, wallImageView.frame.size.width, 225);
[wallImageView addSubview:userImage];
here is code below
-(void)loadWallViews
{
//Clean the scroll view
for (id viewToRemove in [self.wallScroll subviews]){
if ([viewToRemove isMemberOfClass:[UIView class]])
[viewToRemove removeFromSuperview];
}
//For every wall element, put a view in the scroll
int originY = 10;
for (PFObject *wallObject in self.imageFilesArray){
//Build the view with the image and the comments
UIView *wallImageView = [[UIView alloc] initWithFrame:CGRectMake(10, originY, self.view.frame.size.width - 20 , 330)]; //self.view.frame.size.height
//[[UIView appearance] setBackgroundColor:[UIColor redColor]]; //added for problem solve
//Add the image
PFFile *image = (PFFile *)[wallObject objectForKey:KEY_IMAGE];
UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]];
userImage.frame = CGRectMake(0, 65, wallImageView.frame.size.width, 225);
[wallImageView addSubview:userImage];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, wallImageView.frame.size.width,55)];
infoLabel.text = [wallObject objectForKey:#"newsTitle"];
infoLabel.font = [UIFont fontWithName:KEY_FONT size:20];
infoLabel.textColor = [UIColor darkGrayColor];
infoLabel.backgroundColor = [UIColor clearColor];
infoLabel.numberOfLines = 0;
[wallImageView addSubview:infoLabel];
//Add the info label (User and creation date)
NSDate *creationDate = wallObject.createdAt;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:KEY_DATEFORMAT];
//Add the comment
UILabel *commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, wallImageView.frame.size.width, 12)];
//commentLabel.text = [NSString stringWithFormat:#"Uploaded by: %#, %#", [wallObject objectForKey:#"NewsDetail"], [df stringFromDate:creationDate]];
commentLabel.text = [NSString stringWithFormat:#": %#, %#", [wallObject objectForKey:#"newsDetail"], [df stringFromDate:creationDate]];
commentLabel.font = [UIFont fontWithName:KEY_FONT size:10];
commentLabel.textColor = [UIColor lightGrayColor];
commentLabel.backgroundColor = [UIColor clearColor];
[wallImageView addSubview:commentLabel];
UILabel *readLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 71 , 50, wallImageView.frame.size.width, 12)];
readLabel.text = #"Read more";
readLabel.font = [UIFont fontWithName:KEY_FONT size:10];
readLabel.textColor = [UIColor blueColor];
readLabel.backgroundColor = [UIColor clearColor];
[wallImageView addSubview:readLabel];
UIButton *faceBtn = [[UIButton alloc] initWithFrame:CGRectMake(2,310, 20, 20)];
[faceBtn setImage:[UIImage imageNamed:#"Facebook.png"] forState:UIControlStateNormal];
[faceBtn addTarget:self action:#selector(share:) forControlEvents:UIControlEventTouchUpInside];
[wallImageView addSubview:faceBtn];
UIButton *twitBtn = [[UIButton alloc] initWithFrame:CGRectMake(32,310, 20, 20)];
[twitBtn setImage:[UIImage imageNamed:#"Twitter.png"] forState:UIControlStateNormal];
[twitBtn addTarget:self action:#selector(share:) forControlEvents:UIControlEventTouchUpInside];
[wallImageView addSubview:twitBtn];
UIButton *tumblrBtn = [[UIButton alloc] initWithFrame:CGRectMake(62,310, 20, 20)];
[tumblrBtn setImage:[UIImage imageNamed:#"Tumblr.png"] forState:UIControlStateNormal];
[tumblrBtn addTarget:self action:#selector(share:) forControlEvents:UIControlEventTouchUpInside];
[wallImageView addSubview:tumblrBtn];
UIButton *yourBtn = [[UIButton alloc] initWithFrame:CGRectMake(92,310, 20, 20)];
[yourBtn setImage:[UIImage imageNamed:#"Flickr.png"] forState:UIControlStateNormal];
[yourBtn addTarget:self action:#selector(share:) forControlEvents:UIControlEventTouchUpInside];
[wallImageView addSubview:yourBtn];
// wallImageView = UIEdgeInsetsMake(0.0f, myCell.frame.size.width, 0.0f, 400.0f);
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 343, self.view.frame.size.width, .8)];
separatorLineView.backgroundColor = [UIColor grayColor];// you can also put image here
[wallImageView addSubview:separatorLineView];
[self.wallScroll addSubview:wallImageView];
originY = originY + wallImageView.frame.size.width + 1;
}
//Set the bounds of the scroll
self.wallScroll.contentSize = CGSizeMake(self.wallScroll.frame.size.width, originY);
//Remove the activity indicator
[self.activityIndicator stopAnimating];
[self.activityIndicator removeFromSuperview];
It's probably this:
[[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]]
Looks like you're getting images synchronously instead of asynchronously.
Instead of using UIImageView, you should use PFImageView, which will download the file asynchronously if it's not already cached.

Custom navigation bar back button hit area

I have implement custom back Navigation bar button.
Codes:
-(UIBarButtonItem*) logicToAddBackButton {
UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"UiNavigationBack"]];
UILabel *label=[[UILabel alloc] init];
[label setTextColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]];
[label setText:#"Home"];
[label sizeToFit];
int space=6;
label.frame=CGRectMake(imageView.frame.origin.x+imageView.frame.size.width+space, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, label.frame.size.width+imageView.frame.size.width+space, imageView.frame.size.height)];
view.bounds=CGRectMake(view.bounds.origin.x+8, view.bounds.origin.y-1, view.bounds.size.width, view.bounds.size.height);
[view addSubview:imageView];
[view addSubview:label];
UIButton *button=[[UIButton alloc] initWithFrame:view.frame];
[button addTarget:self action:#selector(eventBack) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
[UIView animateWithDuration:0.33 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
label.alpha = 0.0;
CGRect orig=label.frame;
label.frame=CGRectMake(label.frame.origin.x+25, label.frame.origin.y, label.frame.size.width, label.frame.size.height);
label.alpha = 1.0;
label.frame=orig;
} completion:nil];
UIBarButtonItem *backButton =[[UIBarButtonItem alloc] initWithCustomView:view];
return backButton;
}
self.navigationItem.leftBarButtonItem = [self logicToAddBackButton];
This is how it look and work fine according to the logic.
Issue: If we click on first half of arrow, the back button do not respond.
Please suggest on this.
Try to set to your button:
button.contentEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
I think you miscalculating frame somewhere.
Why don't you add UIButton instead? It will be much easier, but without label animation.
UIButton *button = [[UIButton alloc] init];
[button addTarget:self action:#selector(eventBack:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Home" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"UiNavigationBack"] forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0] forState:UIControlStateNormal];
[button sizeToFit];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
return backButton;

Resources