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.
Related
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.
I am new to this iphone development .I am now stuck with a problem .In my application i require coverflow in which multiple labels should be shown.So for that i added an image as a sub view for view and then added the labels as a sub view for the image view.Every thing works fine for the first 7 elements But when i scroll it is showing the same elements again
I am using
https://github.com/nicklockwood/iCarousel
this to attain coverflow
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(ReflectionView *)view
{
UIImageView *imageView =nil;
UILabel *yourLabel=nil;
UILabel *yourLabel1=nil;
UILabel *yourLabel2=nil;
cardAvailableDataObject *singleCard=[self.cards objectAtIndex:index];
if (view == nil)
{
//set up reflection view
view = [[[ReflectionView alloc] initWithFrame:CGRectMake(0,0,200,self.view.frame.size.width/1.42)] autorelease];
imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(0,0,200,self.view.frame.size.width/1.42)];
[view addSubview:imageView];
yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -5, 200, 50)];
yourLabel.textAlignment = UITextAlignmentCenter;
[yourLabel setTextColor:[UIColor colorWithRed:(38/255.f) green:(171/255.f) blue:(226/255.f) alpha:1.0f]];
[yourLabel setBackgroundColor:[UIColor clearColor]];
[yourLabel setFont:[UIFont fontWithName: #"Trebuchet MS" size: 17.0f]];
[imageView addSubview:yourLabel];
yourLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(90, 40, 300, 20)];
[yourLabel1 setTextColor:[UIColor blackColor]];
[yourLabel1 setBackgroundColor:[UIColor clearColor]];
[yourLabel1 setFont:[UIFont fontWithName: #"Trebuchet MS" size: 12.0f]];
[imageView addSubview:yourLabel1];
yourLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(90, 61, 300, 20)];
[yourLabel2 setTextColor:[UIColor blackColor]];
[yourLabel2 setBackgroundColor:[UIColor clearColor]];
[yourLabel2 setFont:[UIFont fontWithName: #"Trebuchet MS" size: 12.0f]];
[imageView addSubview:yourLabel2];
}
else
{
imageView = [[view subviews] lastObject];
yourLabel = [[imageView subviews] lastObject];
yourLabel1 = [[imageView subviews] lastObject];
yourLabel2= [[imageView subviews] lastObject];
}
yourLabel.text=singleCard.name;
yourLabel2.text=singleCard.companyname;
yourLabel1.text=singleCard.designation;
imageView.image=[profile objectAtIndex:index];
return view;
}
This is my code .Can any one suggest how to solve this
We're using custom fonts for the titleView in the navigation bar.
Somehow Apple always draws this font too high.
How do I correct for this strange offset you get when you are using custom fonts in a navbar?
I used setTitleVerticalPositionAdjustment:forBarMetrics:.
Compatibility: available starting from iOS 5.
Your can set a new view as titleView, then add a new label to it:
UIView * customTitleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 40.0f)];
UILabel * customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 200.0f, 20.0f)];
[customLabel setBackgroundColor:[UIColor clearColor]];
[customLabel setTextColor:[UIColor whiteColor]];
[customLabel setFont:[UIFont systemFontOfSize:12.0f]];
[customLabel setTextAlignment:UITextAlignmentCenter];
[customLabel setText:#"Your Text"];
[customTitleView addSubview:customLabel];
[customLabel release];
[self.navigationItem setTitleView:customTitleView];
[customTitleView release];
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;
}
i am trying to upload 8-10 thumbnail images on UIButton. The images are loaded directly via Links to my server for eg. www.abc.com/fire.png. I have placed these UIButtons inisde a Scrollview. the following code is how i achieve it. but whenever this method gets called my applications hangs up as i guess the images take time to load on the buttons. How can i stop my app from getting stuck for few seconds??
- (void)loadSCRView
{
[self.view addSubview:scrollView];
for (i = 0; i < [myEngine.logoUrlArr count]; i++)
{
NSString *imageName = [NSString stringWithFormat:#"%#",[myEngine.logoUrlArr objectAtIndex:i]];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:imageName] options:NSDataReadingUncached error:nil]];
UIButton *btn = [[UIButton alloc]init];
[btn setImage:image forState:UIControlStateNormal];
[btn setFrame:CGRectMake(x, 4, 57, 57)];
x=x+ 70.00;
btn.tag = i;
[scrollView addSubview:btn];
[btn addTarget:self action:#selector(click:) forControlEvents:UIControlEventTouchDown];
UILabel *label = [[UILabel alloc]init];
label.text = [myEngine.nameArr objectAtIndex:i];
[label setFont:[UIFont fontWithName:#"Helvetica" size:12]];
[label setTextColor:[UIColor whiteColor]];
[label setBackgroundColor:[UIColor clearColor]];
[label setFrame:CGRectMake(btn.frame.origin.x , 59, 70, 20)];
//[label setFrame:CGRectMake(100 , 59, 70, 20)];
y=y+ 100.00;
[scrollView addSubview:label];
[btn release];
[label release];
}
You should try to fetch these images (preferably in a background thread) before the scroll view is displayed. Save these on the disk & use them in the scroll view. A network operation will generally not be that fast that you don't observe a lag.
HTH,
Akshay
To avoid freezing you have to go with NSOperationQueue. Here is a good and appropriate example...
You can use threads so that download the image in the background thread & cache it.So that next time your performance will be good.