Default MPVolumeView Style - ios6

Why iOS 6 SDK still uses old MPVolumeView control's style. I want to use default style like in Apple's Default Music application.
Old one:
New one:
Is there any way to use new one in my project?
Thank you!

There is an another way to do this without using an UISlider control.
UIImage *minImage = [UIImage imageNamed:#"bar-bg"];
UIImage *maxImage = [UIImage imageNamed:#"bar-bg-active"];
UIImage *tumbImage= [UIImage imageNamed:#"circle"];
// 276 x 14 px images used for min and max
// so i need to make the images into very small images by making resizable otherwise it strechs very ugly
minImage = [minImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
maxImage = [maxImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 20)];
[volumeManager setMinimumVolumeSliderImage:minImage forState:UIControlStateNormal];
[volumeManager setMaximumVolumeSliderImage:maxImage forState:UIControlStateNormal];
[volumeManager setVolumeThumbImage:tumbImage forState:UIControlStateNormal];
And volumeManager is
#property (strong, nonatomic) IBOutlet MPVolumeView *volumeManager;

Related

IOS: set a property in iOS7

In my app I have this property (and its #synthesize in .m)
#property (nonatomic, strong) IBOutlet UILabel *titleHeader;
in a secondViewController.
The problem is that in iOS 7 if from firstViewController I do:
[secondViewController.titleHeader setText:#"title"];
it don't work, in iOS 6 it work.
why?
EDIT
I do it:
SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil code:[object code]];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController.titleHeader setText:[object name]];
[secondViewController.headerView setBackgroundColor:colorHeaderGallery];
The views of secondViewController have not been loaded yet when you set them.
You can verify this by querying for the value of secondViewController.titleHeader after pushing the view controller to the navigation stack.
As a fix, you can declare a property in secondViewController
#property (nonatomic, strong) NSString *titleHeaderText;
then set that property instead of secondViewController.titleHeader setText
e.g.
secondViewController.titleHeaderText = [object name];
After that, in your secondViewController's viewDidLoad method, you can set the text of your label.
[self.titleHeader setText:self.titleHeaderText ];
EDIT:
The behavior of pushViewController seems to have changed in iOS 7.
I have tried and replicated your issue.
If you do not want the above change, a workaround is by accessing the view of secondViewController, so that its views will be loaded before you call label setText.
e.g.
SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil code:[object code]];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController view];
[secondViewController.titleHeader setText:[object name]];
[secondViewController.headerView setBackgroundColor:colorHeaderGallery];

using saved GPS coordinates from CLLocation to plot on the iPhone map

I have been using core data to save the user's location for various times in a table view. Now that I can actually get the location details (coordinates mainly) at various times, I would like to plot the coordinates that are available at each time on a MapView (No overlays, just a single point to just point the location at that time). I have the coordinates (one latitude and one longitude value) available, but I would like to know how to plot them on the MapView.
Just to put my question simply, How one can plot the coordinates on a mapview ?
I just browsed through SO and I was not able to find the exact solution that would solve my problem ! Any help will be much appreciated.
Thanks for your time !
Regards,
Raj.
With the help of MKAnnotation, this problem can be solved. Thanks to #Craig and Vishal Kurup !
Create an annotation class as a subclass of NSObject.
in Annotation.h:
#interface Annotation : NSObject <MKAnnotation>
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, assign) NSString *title;
#property (nonatomic, assign) NSString *subtitle;
#end
It should conform to MKAnnotation and the three properties are the ones that are required when conforming to MKAnnotation class. Declare those and synthesize them in the .m file.
In the MapHistoryViewController implementation file, we need to add few lines of codes to view the annotation at the required coordinates.
MapHistoryViewController.m:
#interface MapHistoryViewController (){
CLLocationCoordinate2D annotationCoord;
Annotation *annotation;
}
#end
#implementation MapHistoryViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// To define coordinate for the annotation
annotationCoord.latitude = mapHistoryLocation.coordinate.latitude;
annotationCoord.longitude = mapHistoryLocation.coordinate.longitude;
annotation = [Annotation alloc];
annotation.coordinate = annotationCoord;
annotation.title = streetAnnotation;
// to display the annotation
[self.mapHistoryView addAnnotation:annotation];
// where mapHistoryView is my MKMapView object
}
//You can set the region too, if you want the map to be focused on the coordinates you have provided
//Hope this will help the people with the same question :)

iCarousel integration to app having Tab bar controller in iOS 6.1

I integrate the iCarousel app with single view application.But when I add the tab bar controller and place this iCarousel code in one tab bar Item viewcontroller.But it does not work(Items are displayed but not scrolled).What is the problem here.
I created iCarousel as below:
iCarousel *categorySubView = [[iCarousel alloc]initWithFrame:CGRectMake(0,200, 300, 125)];
categorySubView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
categorySubView.delegate = self;
categorySubView.dataSource = self;
categorySubView.type=iCarouselTypeRotary;
[self.view addSubview:categorySubView];
I am using the following delegae and data source methods:
-(NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return 5;
}
- (UIView *) carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
UIView *sampleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 300)];
sampleView.backgroundColor=[UIColor whiteColor];
UILabel *labelis=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 20)];
labelis.backgroundColor=[UIColor clearColor];
labelis.text=#"8Apr-14Apr";
[sampleView addsubView:labelis];
return sampleView;
}
Please suggest me.
Thanks inadvance
I notice that your carousel view is much smaller than the size of the items inside it (it's only 125 points high).
iCarousel can draw outside of its bounds, but it cannot detect touch events outside of its bounds, so that might be why you are having trouble scrolling.
A good way to debug this is to set the carousel.clipsToBounds = YES, that way what it draws will match what is touchable. Another option is to set the carousel.backgroundColor so you can see what part of it is touchable on screen.
Another thing to check is that the view that you've placed the carousel inside has userInteractionEnabled set to YES.

Pull-to-refresh in UICollectionViewController

I want to implement pull-down-to-refresh in a UICollectionViewController under iOS 6. This was easy to achieve with a UITableViewController, like so:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(startRefresh:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
The above implements a nice liquid-drop animation as part of a native widget.
As UICollectionViewController is a "more evolved" UITableViewController one would expect somewhat of a parity of features, but I can't find a reference anywhere to a built-in way to implement this.
Is there a simple way to do this that I'm overlooking?
Can UIRefreshControl be used somehow with UICollectionViewController despite the header and docs both stating that it's meant to be used with a table view?
The answers to both (1) and (2) are yes.
Simply add a UIRefreshControl instance as a subview of .collectionView and it just works.
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(startRefresh:)
forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
That's it! I wish this had been mentioned in the documentation somewhere, even though sometimes a simple experiment does the trick.
EDIT: this solution won't work if the collection is not big enough to have an active scrollbar. If you add this statement,
self.collectionView.alwaysBounceVertical = YES;
then everything works perfectly. This fix taken from another post on the same topic (referenced in a comment in the other posted answer).
I was looking for the same solution, but in Swift. Based on the above answer, I have done the following:
let refreshCtrl = UIRefreshControl()
...
refreshCtrl.addTarget(self, action: "startRefresh", forControlEvents: .ValueChanged)
collectionView?.addSubview(refreshCtrl)
Not forgetting to:
refreshCtrl.endRefreshing()
I was using Storyboard and setting self.collectionView.alwaysBounceVertical = YES; did not work. Selecting the Bounces and Bounces Vertically does the job for me.
The refreshControl property has now been added to UIScrollView as of iOS 10 so you can set the refresh control directly on collection views.
https://developer.apple.com/reference/uikit/uiscrollview/2127691-refreshcontrol
UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:#selector(refreshControlAction:) forControlEvents:UIControlEventValueChanged];
self.collectionView.refreshControl = refreshControl;
mjh's answer is correct.
I ran into the issue where if the the collectionView.contentSize was not larger then the collectionView.frame.size, you can not get the collectionView to scroll. You can not set the contentSize property either (at least I couldn't).
If it can't scroll, it won't let you do the pull to refresh.
My solution was to subclass UICollectionViewFlowLayout and overide the method:
- (CGSize)collectionViewContentSize
{
CGFloat height = [super collectionViewContentSize].height;
// Always returns a contentSize larger then frame so it can scroll and UIRefreshControl will work
if (height < self.collectionView.bounds.size.height) {
height = self.collectionView.bounds.size.height + 1;
}
return CGSizeMake([super collectionViewContentSize].width, height);
}

Segmented control tintColor in iOS 6

I have a segmented control with 8 segments. I can change the default tint-color of the whole control, BUT can I set a different color for each segment in the control? I found a tutorial that worked in 5.1 with a new class that calls this method,
-(void)setTintColor:(UIColor*)color forTag:(NSInteger)aTag{}
But it doesn't work in iOS 6. Any ideas?
This issue has been fixed here. I could not paste the source code due to formatting issues.
Sample code here.
EDIT: added comment & code from link and fixed formatting. ~olie
Its a hacky fix. This will work. Place your code in ViewDidAppear. That will do the trick.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
dispatch_async(dispatch_get_main_queue(), ^{
for (int i = 0 ; i < [segmentControl.subviews count] ; i++)
{
if ([[segmentControl.subviews objectAtIndex: i] isSelected] )
{
[[segmentControl.subviews objectAtIndex: i] setTintColor: [UIColor blackColor]];
break;
}
}
});
}
You can set different segment image and color for each segment. For color you may use:
//get the subviews of the segmentedcontrol
NSArray *arri = [segmentedControl subviews];
//change the color of every subview(segment) you have
[[arri objectAtIndex:0] setTintColor:[UIColor redColor]];
[[arri objectAtIndex:1] setTintColor:[UIColor greenColor]];
Hope that solves the problem.
You are right...
iOS 6 doesn't support subviews for segmented control....
I have an alternative for you:
CGRect rect = CGRectMake(0, 0, 80, 44);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,
[[UIColor redColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[segment setImage:img forSegmentAtIndex:0];
You need to have core graphics framework added to the project.
We can draw an image for segment at index.... But if you use this, you won't be able to add text using segment title. You will need to draw text also over the image 'img' used above.
Please share if you get any other way of doing it.
UiSegmentedControl has a property 'segmentedControlStyle' (deprecated in iOS7) that affect the behavior of 'tintColor'
the possible styles are:
UISegmentedControlStylePlain,
UISegmentedControlStyleBordered,
UISegmentedControlStyleBar,
UISegmentedControlStyleBezeled,
but actually in iOS6 'Bezeled' (deprecated) is equal to 'Bar'
with the first two styles there is no way to change have applied the 'tintColor', to customize it you need to change the images for each segment using:
- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment;
in this way you will obtain a completely custom segmented control
But if the defaul is enough for your design you can just use the style
UISegmentedControlStyleBar
and the 'tintColor' property will take effect and you will obtain a colored segmented control applying the tint depending to the selected segment and all the other benefits letting the system dial with it.
Here is an easy solution setting a red color and compatible with iOS 6.
for ( UIView *segmentView in [segmentedControl subviews] ) {
if ( [segmentView respondsToSelector:#selector(setTintColor:)] ) {
[segmentView performSelector:#selector(setTintColor:)
withObject:[UIColor redColor]];
}
}

Resources