I'm using the ZBar SDK to read QR codes on iPhone, however I added a button in that view. But the button is not working! Even i tap the button it doesn't go to the action method of that button. Where is the problem actually? Thanks in advance for the help.
-(UIView *)setSettingsButton
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[view setBackgroundColor:[UIColor clearColor]];
UIToolbar *myToolBar = [[UIToolbar alloc] init];
UIBarButtonItem *button=[[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStyleBordered target:self action:#selector(settingsAction)];
[myToolBar setItems:[NSArray arrayWithObjects:button,nil]];
settingsLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 37, 281, 77)];
[settingsLabel setFont:[UIFont fontWithName:#"Arial-BoldMT" size:16]];
[settingsLabel setTextAlignment:UITextAlignmentCenter];
[settingsLabel setBackgroundColor:[UIColor clearColor]];
[settingsLabel setTextColor:[UIColor blueColor]];
[settingsLabel setNumberOfLines:1];
[settingsLabel setText:#"For settings scan admin QR"];
[view addSubview:settingsLabel];
settingsLabel.hidden = YES;
[myToolBar setBarStyle:UIBarStyleDefault];
CGRect toolBarFrame;
toolBarFrame = CGRectMake(0, 436, 320, 44);
[myToolBar setFrame:toolBarFrame];
[view addSubview:myToolBar];
return view;
}
-(void)settingsAction
{
settingsLabel.hidden = NO;
}
I can't see where the problem is, but if it helps, I've customized zBar camera views without any problems.
The most likely answer is that a clear views is obscuring the tool-bar view. Here's a library for debugging UIViews: https://github.com/domesticcatsoftware/DCIntrospect
I had the same problem once. It was because my view was too big. Try to change the view's size like UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];, you'll see if it works.
Related
I am attempting to add a UIToolbar to my cameraOverlayView for a custom imagePickerController. This is the code I want to use:
[self.imagePickerController.cameraOverlayView addSubview:self.topToolbar];
When trying to add a UIToolbar, nothing shows up. Encapsulating it into a UIView and setting it to the view property works if I use:
[self.imagePickerController.cameraOverlayView addSubview:self.view];
But this limits me to using one view for my overlay when I want to add several. I understand I can encapsulate everything into one big view, however when I do that, my bottom toolbar does not appear properly.
Has anyone had success in adding a UIToolbar as a subview to a cameraOverlayView?
i think you need a view to put all the things you need in your cameraOverlay.
for example:
TempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
TempView.alpha = 1.0;
anImageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#""]];
anImageView1.frame = CGRectMake(0, 0, anImageView1.image.size.width, anImageView1.image.size.height-50);
anImageView1.hidden = NO;
anImageView1.alpha = 1.0f;
tabBarHolder = [[UIImageView alloc]init];
tabBarHolder.backgroundColor = [UIColor blackColor];
tabBarHolder.frame = CGRectMake(0, 415, 320, 80);
tampBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 430, 35, 35)];
[tampBtn setBackgroundImage:[UIImage imageNamed:#"iconBack.png"] forState:UIControlStateNormal];
[tampBtn addTarget:self
action:#selector(xup)
forControlEvents:UIControlEventTouchUpInside];
ctampBtn = [[UIButton alloc] initWithFrame:CGRectMake(145, 430, 35, 35)];
[ctampBtn setBackgroundImage:[UIImage imageNamed:#"iconCamera.png"] forState:UIControlStateNormal];
[ctampBtn addTarget:self
action:#selector(takephoto)
forControlEvents:UIControlEventTouchUpInside];
[TempView addSubview:ctampBtn];
[TempView addSubview:tampBtn];
[TempView addSubview:anImageView1];
[TempView addSubview:tabBarHolder];
[TempView bringSubviewToFront:tabBarHolder];
[TempView bringSubviewToFront: ctampBtn];
[TempView bringSubviewToFront:tampBtn];
imagePicker.cameraOverlayView =TempView;
I am trying to add a UILabel programmatically into my UIToolBar but it dose not seem to be appearing. This is what I am doing with my code.
- (void) viewWillAppear:(BOOL)animated
{
// Create custom toolbar at top of screen under navigation controller
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
matchingSeriesInfoToolBar = [UIToolbar new];
[matchingSeriesInfoToolBar sizeToFit];
CGFloat toolbarHeight = 30;
CGRect mainViewBounds = [[UIScreen mainScreen] applicationFrame];
[matchingSeriesInfoToolBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 0, CGRectGetWidth(mainViewBounds), toolbarHeight)];
matchingSeriesInfoToolBar.tintColor = [UIColor darkGrayColor];
[self.view addSubview:matchingSeriesInfoToolBar];
// Create size of uitableview (to fit toolbar.
[matchingSeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
[self.view addSubview:matchingSeriesTableView];
// Ad UILabel to the toolbar
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:manufSelectionLabel];
matchingSeriesInfoToolBar.items = [NSArray arrayWithObject:textFieldItem];
manufSelectionLabel.text = #"Hello World!";
[super viewWillAppear:animated];
}
So pretty much I have created a custom toolbar which I have changed the usual location from the bottom of the screen, to appear under the UINavigationController, this is also added to the view like this so it animated properly in the view transitions..
After which I create the size of the tableview so that it appears after the custom toolbar..
then from there I am trying to add a UILabel to the toolbar.. but for some reason its not working out.
Any help would be greatly appreciated.
You must actually create the label somewhere. This code works just fine.
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:toolbar];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
label.backgroundColor = [UIColor clearColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
toolbar.items = [NSArray arrayWithObject:item];
label.text = #"Hello World";
In the code you posted you don't ever make a UILabel. Your comment says Ad UILabel to the toolbar but you then proceed to make a UIBarButtonItem with a custom view manufSectionLabel.
Where is the code which creates manufSectionLabel?
PS This line does nothing :
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
because at that point matchingSeriesInfoToolbar is nil - you haven't made it yet!
On the iPhone I like how action sheets take up the entire width of the screen and you can choose the height of it (so I can include other views). Here is my entire method that creates the action view (you probably on need the las few lines though)...
-(void)createActionView {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:#"Done",nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
UIButton *downHoleScore = [UIButton buttonWithType:UIButtonTypeCustom];
downHoleScore.frame = CGRectMake(93, 75, 35, 35);
[downHoleScore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
downHoleScore.backgroundColor = [UIColor clearColor];
downHoleScore.tag=1;
[downHoleScore addTarget:self action:#selector(HoleScoreButtonTap:) forControlEvents:UIControlEventTouchUpInside];
[downHoleScore setBackgroundImage:[UIImage imageNamed:#"Left-Down-Arrow.png"] forState:UIControlStateNormal];
[actionSheet addSubview:downHoleScore];
UIButton *upHoleScore = [UIButton buttonWithType:UIButtonTypeCustom];
upHoleScore.frame = CGRectMake(193, 76, 35, 35);
[upHoleScore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
upHoleScore.backgroundColor = [UIColor clearColor];
upHoleScore.tag=2;
[upHoleScore addTarget:self action:#selector(HoleScoreButtonTap:) forControlEvents:UIControlEventTouchUpInside];
[upHoleScore setBackgroundImage:[UIImage imageNamed:#"Right-Up-Arrow.png"] forState:UIControlStateNormal];
[actionSheet addSubview:upHoleScore];
golferScoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 70, 45, 45)];
golferScoreLabel.text = #"0";
golferScoreLabel.backgroundColor = [UIColor clearColor];
golferScoreLabel.font = [UIFont fontWithName:#"ChalkDuster" size: 45.0];
golferScoreLabel.textAlignment = UITextAlignmentCenter;
golferScoreLabel.shadowColor = [UIColor grayColor];
golferScoreLabel.shadowOffset = CGSizeMake(1,1);
golferScoreLabel.textColor = [UIColor whiteColor];
[actionSheet addSubview:golferScoreLabel];
CGRect pickerFrame = CGRectMake(0, 120, 0, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet showFromRect:CGRectMake(0, 0, 320, 585) inView:self.view animated:YES];
}
How would I edit this to make it look more like an action view on the iPhone?
In this code...
[actionSheet showFromRect:CGRectMake(0, 0, 320, 585) inView:self.view animated:YES];
That above is where I think I am messing up how would I make this cover the entire bottom half of the screen on the iPad?
Read the docs on UIActionSheet. On iPad, they are presented in popovers.
If you want behavior like on the iPhone, I think you'll have to write your own actionSheet-like view and animations (which is really not that hard, it just takes a little time).
Anyway, presenting actionSheets on an iPad with the full width wouldn't be very good design anyway - you probably don't want buttons that are as wide as the whole screen. I would advise you to rethink your design.
But maybe you don't really want actionSheets. Maybe you only want that nice animation, to present some content of your own like that? That's certainly doable (see above), but then you have asked the wrong question.
I am using zbar SDK to scan QR code, can anyone help me figure out how to add a market and a label with the zbar SDK?
I did it like this for my app.
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.cameraOverlayView = [self CommomOverlay];
-(UIView *)CommomOverlay{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIImageView *TopBar = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,58)];
[TopBar setImage:[UIImage imageNamed:#"topbar.png"]];
[view addSubview:TopBar];
UILabel *Toplabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, 300, 30)];
[Toplabel setFont:[UIFont fontWithName:#"Arial-BoldMT" size:11]];
[Toplabel setTextAlignment:UITextAlignmentCenter];
[Toplabel setBackgroundColor:[UIColor clearColor]];
[Toplabel setTextColor:[UIColor colorWithRed:76/255.0 green:76/255.0 blue:76/255.0 alpha:1.0]];
[Toplabel setNumberOfLines:1];
[Toplabel setText:#"Place QR code inside the viewfinder to scan "];
[TopBar addSubview:Toplabel];
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(60,150,193,170)];
[FrameImg setImage:[UIImage imageNamed:#"frame.png"]];
[view addSubview:FrameImg];
return view;
}
You wouldn't use zbar for this, you would just use the normal Xcode label. Watch this tutorial, its great and will teach you how to use the label. The version of Xcode they use in the tutorial may be a little old.
I'm trying to place an image (a square bracket for the focus) in the camera view of the ZBAR SDK? Can anyone please help me what needs to be done? thanks
You can set overlay of camera screen to set the cameraOverlayView property. Design a view as per your requirement and assign it:
reader.cameraOverlayView = [self CommomOverlay];
-(UIView *)CommomOverlay{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIImageView *TopBar = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,58)];
[TopBar setImage:[UIImage imageNamed:#"topbar.png"]];
[view addSubview:TopBar];
UILabel *Toplabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, 300, 30)];
[Toplabel setFont:[UIFont fontWithName:#"Arial-BoldMT" size:11]];
[Toplabel setTextAlignment:UITextAlignmentCenter];
[Toplabel setBackgroundColor:[UIColor clearColor]];
[Toplabel setTextColor:[UIColor colorWithRed:76/255.0 green:76/255.0 blue:76/255.0 alpha:1.0]];
[Toplabel setNumberOfLines:1];
[Toplabel setText:#"Scan now "];
[TopBar addSubview:Toplabel];
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(60,150,193,170)];
[FrameImg setImage:[UIImage imageNamed:#"frame.png"]];
[view addSubview:FrameImg];
return view;
}