What I am trying to achieve is an if statement which finds out if AirPlay is enabled or not.
I know that the property is allowsAirPlay and that it comes from MPVolumeView. But I am stuck from here on in. Any help is much appreciated!
if (allowsAirPlay){
UIImageView *streamBG = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"img1.jpg"]];
[self.view addSubview:streamBG];
[self.view sendSubviewToBack:streamBG];
streamBG.frame = CGRectMake(0, 0, 320, 480);
[streamBG release];
} else {
UIImageView *emailBG_AP = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"background_schedule.jpg"]];
[self.view addSubview:emailBG_AP];
[self.view sendSubviewToBack:emailBG_AP];
emailBG_AP.frame = CGRectMake(0, 0, 320, 480);
[emailBG_AP release];}
}
allowsAirPlay is a property in MPMoviePlayerController which you can flip YES and NO. The value won't tell you whether there are AirPlay enabled devices in range. I don't think there are public APIs that tell give you that information.
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.
Im having troubles to set a imagebackground on a TTView.
Here is the code i found on internet, but it only shows a black square.
- (TTView *) monthBar {
if (!_monthBar) {
_monthBar = [[[TTView alloc] init] autorelease];
_monthBar.style = TTSTYLE(calendarMonthBarStyle);
_monthBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
TTImageView *imageView = [[TTImageView alloc]initWithFrame:CGRectMake(0, 0, 480, 20)];
[imageView setDefaultImage:[UIImage imageNamed:#"picture.png"]];
[self.monthBar addSubview:imageView];
[imageView release];
[self addSubview: _monthBar];
}
return _monthBar;
}
If someone knows how to solve it, please help me.
Thanks!
Using an imageView as subview of _monthBar should normally not be necessary. You should instead use the image as background in the style. Your style seems to be called calendarMonthBarStyle. You'll need to add a TTImageStyle referencing "picture.png" there.
It's easy to change background color of a searchbar.But, I have no idea how to change its background image.There is no direct method.
I need help...............
I appreciate any given idea...
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIImageView* iview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"test.png"]];
iview.frame = CGRectMake(0, 0, 320, 44);
[bar insertSubview:iview atIndex:1];
[iview release];
[self.view addSubview:bar];
[bar release];
searchBar.backgroundImage = [UIImage imageNamed:#"searchBackground"];
if you want to use an image as the background of the search bar, you can use,
searchBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"search_bg.png"]];
I am using a UISearchBar and once the user taps the bar (and the keyboard pops up) I want the everything besides the keyboard and UISearchBar to be greyed out. Similar to safari when the search is selected. I do not need past searches. See here:
Anyone have any ideas? I've looked through the questions here on StackOverflow and I can't find anything specific.
Thanks!
You can create a UIView that contains the UISearchBar. And then you can set UIView's backgroundColor to get the gray background.
And here's some sample code:
UIView *view1 = [[UIView alloc] init];
view1.frame = CGRectMake(0, 20, 320, 460);
view1.backgroundColor = [UIColor grayColor];
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.frame = CGRectMake(0, 0, 320, 50);
[view1 addSubview:searchBar];
[searchBar release];
[self.window addSubview:view1];
[view1 release];
I have seen it done on some apps, where the navigation bar is actually smaller than the default 44px, and there is a UIView (which has functionality) above the nav bar...
I want more than a custom background image, which I did manage to figure out how to do, but I dont know where to start getting something like this done.
Any help is greatly appreciated :)
Mark
I found a sort of way to do this:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 32.0f)];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
UIImageView *back = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"logo.png"]];
[back setFrame: CGRectMake(0, 0, 320, 20)];
[tempView addSubview: back];
[[self view] addSubview: tempView];
[[self view] addSubview: navBar];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle: #"Controls"];
[navBar pushNavigationItem:navItem animated:NO];
which seems to do the trick, although I cannot seem to figure out how to get this 'into' the navigationController so that back buttons work, at the moment I have to manually insert a leftBarButtonItem into the navItem, the back button never seems to show...
Yes you can,
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 32.0f)];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
navBar.navigationBar.layer.zPosition =-1;
self.view insertSubview:navBar atIndex:[[self.view subviews] count]];
[self.view insertSubview:tempView atIndex:[[self.view subviews] count]];