Scope Bar for UITableView like App Store? - ios

Does anyone know how to add a scope bar to a UITableView?
The App Store app does this sometimes, like in the picture below.
I would like to use this scope bar to add sorting options for the elements in the UITableView. This would be more convenient than having a toolbar with a UISegmentControl.
I just don't know how to implement this. I don't even know the name of the element (I'm calling it scope bar because it looks just like the scope bar of a UISearchBar, but it is not).

Actually, unlike what others have said, this UISegmentedControl's .segmentedControlStyle property is set to an undocumented value of 7.
theSegCtrl.segmentedControlStyle = 7;
But #Macatomy's answer is more AppStore-safe (although Apple can't detect this anyway).

Probably you already solved this issue but I believe this can be helpful for other people.
Inside your ViewController that you use in that TableViewController, you should insert the following code:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSArray *segmentTextContent = [NSArray arrayWithObjects: #"one",#"two",#"three", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.frame = CGRectMake(2, 5, 316, 35);
[self.segmentedControl addTarget:self action:#selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; //changes the default style
self.segmentedControl.tintColor = [UIColor darkGrayColor]; //changes the default color
self.segmentedControl.enabled = true;
self.segmentedControl.selectedSegmentIndex = 0;
return self.segmentedControl;
}
That inserts a segmented control as the table header, which (if you wish) will also bounce when you reach the list top and at the same time will always remain visible while you scroll in your list.
Hope it helps.

The element is a UISegmentedControl with the UISegmentedControlStyleBar style. You can set the tintColor property to get the color desired. Just put the view above the table view and you can get something that looks like that screenshot.

UISegmentedControl
You create it, set up its segments, and set its delegate. The delegate then takes some sort of action every time the selected segment changes.

Related

custom UIcollectionViewCell, using view to control color changes

I was going thru the tutorial here: http://pinkstone.co.uk/how-to-build-a-uicollectionview-in-ios-8/
And saw a part that looked great because it makes something simple, use of views to show color changes of selected/unselected items.-
(void)awakeFromNib {
// background color
UIView *bgView = [[UIView alloc]initWithFrame:self.bounds];
self.backgroundView = bgView;
self.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"blue"]];
// selected background
UIView *selectedView = [[UIView alloc]initWithFrame:self.bounds];
self.selectedBackgroundView = selectedView;
self.selectedBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"pink"]];
}
The author showed that this is a simple approach that eliminates the need to manage the state of the cells.
Q. I want to change the color using this method during the highlight process. However, didHighlightItemAtIndexPath is in the CollectionViewController and I'd like to have it use the same process.
Basically what it does is change from one color to another based on selected/unselected. I'd like to use the add a color to indicate the in between state of being highlighted/unhighlighted.
I checked all the methods that are in cell that use UIView, and there is nothing for highlighted/unhighlighted.
Any ideas on an approach that has the advantages of using cell methods? Can I call a custom method from the viewcontroller method and load a view there?
You might think of this as a "press and hold" that changes the color when it's being held.
A UIView wouldn't know anything about it's selected or unselected state since it's a very elemental component and not specific to controls that allow selection. The UICollectionViewCell does have a selected property though, so that would be the right place to change these characteristics. Looking at the docs it seems like either tapping into setSelected or selectedBackgroundView would give you a good opportunity to customize the L&F of selected cells. There's also a highlighted state in case you might also be looking for that.

UIButton with highlighted bottom border

I am trying to implement custom buttons something like in the picture, when clicking on button it highlight with text color and bottom border. could anyone help me with that?
The image you've shown is probably a UISegmentedControl. That's how you tap something so that it stays selected (and other choices are deselected). It's easy to customize a segmented control so that the background image is different when a segment is selected vs. when it is not.
Yes matt is right, here's a third party segment control which I have used in one of my app. It's nice and same as your requirement. Oh yes, it's written in Obj-C only. https://github.com/HeshamMegid/HMSegmentedControl
HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:#[#"Search",#"Broadcast"]];
segmentedControl.frame = CGRectMake(10, 10, 300, 60);
[segmentedControl addTarget:self action:#selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentedControl];
- (void)segmentedControlChangedValue:(id)sender {
//handle segment selection
}

Can't remove UILabel from UINavigationController.view

I'm adding a tiny marker under my UINavigationController title so the user will know that the title is tappable. You can see in the code below how I add this label to the navigation bar.
_labelCalendarMenuArrow = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2 - 5, 30, 10, 26)];
_labelCalendarMenuArrow.text = #" ̬";
_labelCalendarMenuArrow.font = [UIFont fontWithName:#"HelveticaNeue" size:30];
_labelCalendarMenuArrow.textAlignment = NSTextAlignmentCenter;
_labelCalendarMenuArrow.textColor = [UIColor whiteColor];
[self.navigationController.view addSubview:_labelCalendarMenuArrow];
The problem is that I'm unable to remove this UILabel from the navigationController.view when leaving this screen. In the code below you can see how I try a few methods for hiding or removing this UILabel, but none of them work... The UILabel will stay in the NavigationController until I go to a different stack of views and come back. Any advice?
- (void)viewWillDisappear:(BOOL)animated {
[_labelCalendarMenuArrow removeFromSuperview];
_labelCalendarMenuArrow = nil;
_labelCalendarMenuArrow.alpha = 0;
}
A simple solution can be to use HIDDEN property
- (void)viewWillDisappear:(BOOL)animated
{
_labelCalendarMenuArrow.hidden=YES;
}
What you are trying to do here is fairly horrific, adding a view within a parent navigation controller's view is against all sense.
Please read apple's human interface guidlines as there is a better solution to signifying that the title is clickable in there. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/
If you still insist on adding a label underneath the navigation bar's title label you should implement a titleView for the navigation item. Within that view you will have to include your own title label to replace the original and then your signifier label underneath.

Customising same UINavigationBar within app multiple times

I am customising UINavigationBar with different color and custom font by using titleTextAttributes. However, when I moved to another view, I would like to use different color from previous with same custom font.
I have used,
[[UINavigationBar appearance] setTitleTextAttributes:mySettings]
in AppDelegate.m. When call same method with newSettings in viewDidLoad of another viewController, it doesn't get reflected.
I am able to change bar color or bar tint color in viewDidLoad of another viewController. However, my title foreground color is not changing. Am I missing anything?
Last solution which I have to have custom titleView. But wanted to avoid it. Any inputs?
[[UINavigationBar appearance] setTitleTextAttributes:mySettings] is a global configuration, so that's the reason why changing it in the other view controllers doesn't work. I believe you won't getting around customizing the titleView property of navigation item,... :/
You can do this by creating a UILabel that has the settings that you want and then assign it to the property:
NSAttributedString *title = [[NSAttributedString alloc] string:"the title" attributes:mySettings];
UILabel *newTitleView = [[UILabel alloc] init];
newTitleView.attributedText = title;
self.navigationItem.titleView = newTitleView;

iOS - UISegmentedControl Strange Behaviour

I have added a UISegmentedControl in the application. The segment control works fine and all i am doing with it is to get its selected state when a value is changes nothing else.
The UISegmentedControl initially looks like this
-
After i show an Reachability Not available state it looks like this
-
But after the application resumes and internet is connected and application resigns active it looks like this
The UISegmentedControl does work properly but the color does not resume its state.
- The Reachibility blocks are in Application Delegates and have nothing to do with the UISegmentControl
EDIT
I have also checked that even after i set the color programatically in
viewDidLoad or viewDidAppear or even in the state changed setting the
TintColor of the UISegmentedControl it insted of an RGBA value it
gives color as ( UIDeviceWhiteColorSpace 0.3 0.8 )
I had a similar problem.. This helped me
You can give it a try
self.segControl.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
this kind of acts like a refresh (what i call it) for the segment control
I had placed this in -(void)viewWillAppear:(BOOL)animated . You can place it in the same method or a method where the control would return after the networking call and alert is dismissed.
Hope this helps.
Use break points to find the solution and then check whether the alpha colour has changed before and after internet connection. Or better you set tint appearance something like this..
#pragma mark - Appearance Methods
-(void)customizeAppearance {
UIColor *appTintColor = [UIColor colorWithRed:20/255.0f green:160/255.0f blue:160/255.0f
alpha:1.0f];
[[UISearchBar appearance] setBarTintColor:appTintColor];
[[UISegmentedControl appearance] setTintColor:appTintColor];
self.window.tintColor = [UIColor colorWithRed:10/255.0f green:80/255.0f blue:80/255.0f
alpha:1.0f];
}
I have got the same situation in my app.
I tried all the appearance methods but nothing seems to work. Instead it is all about showing the alertview at the right place. The alertview when shown causes the os to set the tintcolor to gray to the all items in the current viewcontroller. If when shown on viewcontroller launch there will be a conflict on which viewcontroller the tintcolor is changed. I guess this is causing the color change bug.
I guess you would have checked the reachability in you viewwillappear and you would have shown the alertview in the viewwillappear method. Instead have a bool value and set is as YES or NO depending on the values and then show the alertview of the internetconnection on viewdidappear by checking the bool value.
This is how i solved mine.
Instead of setting the color on interface builder try setting it programatically for the component.
Doing it this way will allow to to use breakpoints to check exactly what is happening after the Reachability notification is done.
You can simply call it on the constructor, for example:
[UIColor colorWithRed:66.0f/255.0f green:79.0f/255.0f blue:91.0f/255.0f alpha:1.0f]
[[UISegmentedControl appearance] setTintColor:appTintColor];
Perhaps you could re-confirm all tintsettings programmatically in the reachability's notification receiver?
-(void)reachabilityChanged:(NSNotification*)note
{
Reachability * reach = [note object];
//set tints and colors either way (isReachable and !isReachable)
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
Remember that UIView in iOS 7 has a tintAdjustmentMode property.
In your case, this property has probably been set on your UISegmentedControl to UIViewTintAdjustmentModeDimmed when the screen was dimmed.
From the documentation of UIView:
If the view’s tintAdjustmentMode property’s value is
UIViewTintAdjustmentModeDimmed, then the tintColor property value is
automatically dimmed.
You must set the divider image whose height and width should be same as the height of segment control, divided into two halves red and blue in your case
use the following code:
[segmentControllerObj setDividerImage:[UIImage imageNamed:#"left.png"] forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segmentControllerObj setDividerImage:[UIImage imageNamed:#"right.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

Resources