Pls help.. i have this button in my subclass, when i addsubview it in my uiview, it cant be clicked, any idea?..thanks
the button in my subclass:
- (void)configureDate{
ChangeButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
ChangeButton.frame= CGRectMake(10, 20, 100, 30);
[ChangeButton setTitle:#"Change Date" forState:UIControlStateNormal];
[ChangeButton addTarget:self action:#selector(changeDate) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:ChangeButton];
}
I added the subclass/button in my uiview:
dateClass = [[DateClass alloc] init];
[dateClass configureDate];
[myView addSubview:dateClass];
[dateClass releaseTable];
the button appears but is not clickable:(
Try this:
[myView addSubview:dateClass];
[myView bringSubviewToFront:dateClass];
Try setting BG color for both dateClass and the ChangeButton button to test.
- (void)configureDate{
ChangeButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
ChangeButton.frame= CGRectMake(10, 20, 100, 30);
[ChangeButton setTitle:#"Change Date" forState:UIControlStateNormal];
[ChangeButton addTarget:self action:#selector(changeDate) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:ChangeButton];
self.backgroundColor=[UIColor redColor];
ChangeButton.backgroundColor=[UIColor yellowColor];
}
Related
i am creating three buttons and one uitextview dynamically but when i run the program its not display on my screen
this my code to create dynamic buttons and textview
-(void)getSmsdisplay
{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UITextView *textview=[[UITextView alloc]init];
[button setTitle:#"Comment" forState:UIControlStateNormal];
[button1 setTitle:#"Share" forState:UIControlStateNormal];
[button1 setTitle:#"Like" forState:UIControlStateNormal];
//listen for clicks
[button addTarget:self
action:#selector(btncomment:)forControlEvents:UIControlEventTouchUpInside];
[button1 addTarget:self
action:#selector(btnShare:)forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self
action:#selector(Like:)forControlEvents:UIControlEventTouchUpInside];
smsdata *data=[[smsdata alloc]init];
[textview setText:data.Data];
[self.view addSubview:textview];
//add the button to the view
[self.view addSubview:button];
[self.view addSubview:button1];
[self.view addSubview:button2];
}
your coding is fine , but u r not added the frame for UIButton and UItextview
-(void)getSmsdisplay
{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UITextView *textview=[[UITextView alloc]init];
button.frame=CGRectMake(20, 50, 200, 50);
button1.frame=CGRectMake(20, 150, 200, 50);
button2.frame=CGRectMake(20, 300, 200, 50);
button.backgroundColor=[UIColor redColor];
button1.backgroundColor=[UIColor grayColor];
button2.backgroundColor=[UIColor blackColor];
[button setTitle:#"Comment" forState:UIControlStateNormal];
[button1 setTitle:#"Share" forState:UIControlStateNormal];
[button2 setTitle:#"Like" forState:UIControlStateNormal];
//listen for clicks
[button addTarget:self
action:#selector(btncomment:)forControlEvents:UIControlEventTouchUpInside];
[button1 addTarget:self
action:#selector(btnShare:)forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self
action:#selector(Like:)forControlEvents:UIControlEventTouchUpInside];
[textview setText:#"karthik"];
[self.view addSubview:textview];
//add the button to the view
[self.view addSubview:button];
[self.view addSubview:button1];
[self.view addSubview:button2];
}
the output is
You are assigning self.view to another UIView instance, which has not been added to the viewController. Note that self.view is already initialised in a viewController and it is dangerous to reassign the same.
Also, you have not set any frames for the Buttons and textview.
The following code should make it work.
-(void)getSmsdisplay
{
UIView *smsView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
[self.view addSubview: smsView]; //The new view needs to be added to something!
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UITextView *textview=[[UITextView alloc]initWithFrame:CGRectMake:(20,20,100,50)];
[button setTitle:#"Comment" forState:UIControlStateNormal];
[button1 setTitle:#"Share" forState:UIControlStateNormal];
[button1 setTitle:#"Like" forState:UIControlStateNormal];
//listen for clicks
[button addTarget:self
action:#selector(btncomment:)forControlEvents:UIControlEventTouchUpInside];
[button1 addTarget:self
action:#selector(btnShare:)forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self
action:#selector(Like:)forControlEvents:UIControlEventTouchUpInside];
smsdata *data=[[smsdata alloc]init];
[textview setText:data.Data];
[smsView addSubview:textview];
button.frame=CGRectMake(20, 50, 200, 50);
button1.frame=CGRectMake(20, 150, 200, 50);
button2.frame=CGRectMake(20, 300, 200, 50);
//add the button to the view
[smsView addSubview:button];
[smsView addSubview:button1];
[smsView addSubview:button2];
}
I tried to set Rounded button with the following but its disappearing from the view. if I removed the
takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
then its displaying the rectangular button. help me to get the RoundedRect Button.
takebtn = [[UIButton alloc]initWithFrame:CGRectMake(30, 325, 250, 40)];
takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[takebtn setTitle:#"Take Photo" forState:UIControlStateNormal];
takebtn.backgroundColor=[UIColor colorWithRed:50.0/255.0 green:205.0/255.0 blue:50.0/255.0 alpha:1.0];
[takebtn addTarget:self
action:#selector(takePhoto:)
forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[nextview addSubview:takebtn];
You need to modify your code like that below:-
takeBtn.layer.cornerRadius = 10; //value can be change accordingly.
takeBtn.clipsToBounds = YES;
Note:- No need to import Quartz framework in ios7
try this
UIButton* takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[takebtn setFrame:CGRectMake(30, 325, 250, 40)];
[takebtn setTitle:#"Take Photo" forState:UIControlStateNormal];
takebtn.backgroundColor=[UIColor colorWithRed:50.0/255.0 green:205.0/255.0 blue:50.0/255.0 alpha:1.0];
[takebtn addTarget:self
action:#selector(takePhoto:)
forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[nextview addSubview:takebtn];
I want to add a UIButton or other type of button to an AVCaptureVideoPreviewLayer.
Here is what I have tried:
[self.view.layer addSublayer:_videoPreviewLayer];
UIButton * sButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 300, 100)];
[sButton setBackgroundColor:[UIColor yellowColor]];
[sButton setTitle:#"Stop" forState:UIControlStateNormal];
[sButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_videoPreviewLayer addSublayer:sLabel.layer];
[_captureSession startRunning];
I also tried something similar with a UIView which was added, even when the AVCapture was not started. I could not however add a subview to that view.
Little late to the party, but I've been working on something similar, so I thought I'd share:
UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(200, 200, 100, 50);
[btn setTitle:#"Hello, world!" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor blueColor]];
[btn becomeFirstResponder];
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, btn);
[self.view addSubview:btn];
So I have a view and in my viewcontoller class I try and add a subview with the following code .
UIButton *test = [[UIButton alloc]initWithFrame:CGRectMake(30, 100, 100, 100)];
[self.view addSubView:test];
Nothing happens, no errors or anything. I know its being called because it is in the viewdidload method. I have a separate class were i subclass uiview could that have anything to do with it?
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
test.frame = CGRectMake(30, 100, 100, 100);
[self.view addSubView:test];
You need to make sure you add all the needed attributes of that button:
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test addTarget:self action:#selector(selector:) forControlEvents:UIControlEventTouchDown];
[test setTitle:#"Button Title" forState:UIControlStateNormal];
test.frame = CGRectMake(30, 100, 100, 100);
[view addSubview:test];
I've been using Interface Builder and storyboard to make my application, but for this signature capturing API, everything was done in code.
I'm trying to implement it to my application, but I can't figure out how to add an UIView and Buttons on to my scrollview.
I got it to appear in my view controller, but it isn't connected to the scrollview at all; it appears on top.
Here's my code.
- (void)viewDidLoad
{
[super viewDidLoad];
CGFloat padding = self.view.frame.size.width/15;
UIView *autoGraphView = [[[UIView alloc] initWithFrame:CGRectMake(padding, 300, 280, 160)] autorelease];
autoGraphView.layer.borderColor = [UIColor lightGrayColor].CGColor;
autoGraphView.layer.borderWidth = 3;
autoGraphView.layer.cornerRadius = 10;
[autoGraphView setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:autoGraphView];
self.autoGraph = [T1Autograph autographWithView:autoGraphView delegate:self];
[autoGraph setLicenseCode:#"4fabb271f7d93f07346bd02cec7a1ebe10ab7bec"];
[autoGraph setShowDate:YES];
[autoGraph setShowHash:YES];
UIButton *clearButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// init withFrame:CGRectMake (50, 300, 200, 60)];
[clearButton setFrame:CGRectMake(padding, 480, 130, 30)];
[clearButton setTitle:#"Clear" forState:UIControlStateNormal];
[clearButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[clearButton addTarget:self action:#selector(clearButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:clearButton];
UIButton *autoDone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// initWithFrame:CGRectMake (50, 300, 200, 60)];
[autoDone setFrame:CGRectMake(150 + padding, 480, 130, 30)];
[autoDone setTitle:#"Done" forState:UIControlStateNormal];
[autoDone setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[autoDone addTarget:self action:#selector(doneButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:autoDone];
}
You need to add the subviews to the scrollview, if the root view of your viewcontroller is not the scrollview, you need to get access to it one way or another, typically through an IBOutlet, and add them that way