Git Product home page Git Product logo

hmsegmentedcontrol's People

Contributors

abelcapable avatar alexandreos avatar crazytonyli avatar gaijin03 avatar goncharik avatar hanishabsigh avatar heshammegid avatar hilalbaig avatar hons82 avatar huynguyencong avatar ikesyo avatar jacksonpan avatar jmkr avatar leontiy avatar lordzsolt avatar maxep avatar miglius avatar mpurland avatar mrtristan avatar nirvana-icy avatar raxityo avatar rbbtsn0w avatar sergey-sportsetter avatar taehongkimkr avatar timbao avatar valeriomazzeo avatar valeriyvan avatar volodg avatar waynett avatar xxycode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hmsegmentedcontrol's Issues

HMSegmentedControlTypeTextImages icon alignment

I think the icons should be at the left of the labels... not in the middle.

hmsegmentedcontrol

 _segmentedControl = [[HMSegmentedControl alloc]
                         initWithSectionImages:@[[UIImage imageNamed:@"place_25"],[UIImage imageNamed:@"directions_16"]]
                         sectionSelectedImages:@[[UIImage imageNamed:@"place_25"],[UIImage imageNamed:@"directions_16"]]
                         titlesForSections:@[@"Place"),@"Directions"]];

    _segmentedControl.frame = CGRectMake(0.0f, 0.0f, frame.size.width, 40.0f);
    _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
    _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    _segmentedControl.selectionIndicatorColor = [UIColor CycleMapColor];
    _segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor cm_veryDarkGrayColor],
                                              NSFontAttributeName : [UIFont CycleMapBoldFontOfSize:12.0f]};
    _segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor CycleMapColor]};

Change size of the buttons with images

I have to set HMSegmentedControl with the 1/2 width of the whole screen, using auto layout. (iphone 5, 6 and 6 plus).

So the width will change according to the screen. and i have fixed sizes of the images.

How to set the button width programmatically and center this images in the center of the buttons

    NSArray *iconsLeftMenu = [[NSArray alloc]initWithObjects:
                              [UIImage imageNamed:@"icon-timeline"],
                              [UIImage imageNamed:@"icon-map"],
                              nil];

    segmentedControl = [[HMSegmentedControl alloc]
                                             initWithSectionImages:iconsLeftMenu
                                             sectionSelectedImages:iconsLeftMenu];


    segmentedControl.frame = CGRectMake(0, 300, 320, 50);
    // Bellow is the width of the HMSegmentedControl
    CGRect frameMenu = headerLeftView.bounds;
    segmentedControl.frame = frameMenu;

    segmentedControl.backgroundColor = [UIColor clearColor];
    segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationNone;
    segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleBox;
    [segmentedControl addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];
    [headerLeftView addSubview:segmentedControl];

captura de tela 2015-01-22 as 17 11 09
captura de tela 2015-01-22 as 17 10 54

Can not change opacity of indicatorBox

I am using the cocoapod and trying to change the opacity of they indicator box. I have changed its color and opacity to 1.0 but it is giving me a color darker than the one I wanted. I also tried going into the HMSegmentedControl.m and changing the value from the commonInit but it is still not working. Any help would be appreciated.

Changing the width to fit the text

I want to change each segment to change the text, how can i achieve this. in the current there is a lot of white space if the text is short?

Best regards

Segmented Control with images stretched

The segments in this control have to be generated dynamically at runtime and the result is the image completely stretched.

My code is
var optionsSegmentedControl = HMSegmentedControl(sectionImages: [UIImage(named: "1")!], sectionSelectedImages: [UIImage(named: "1")!])

See attachment :

screen shot 2015-02-15 at 10 22 18 pm

iOS5.1 support

Hi,

I saw you took extra care in multiple instances to avoid using -[NSString sizeWithAttributes:] as to maximise compatibility with older iOS versions. I found a place though where this has been done differently and becomes an issue on iOS 5.1: HMSegmentedControl.m lines 226 and 227. The symbol NSFontAttribueName doesn't exist on this older version of iOS5 and it makes the app crash on startup because it cannot resolve the external symbol. If you agree to solve this I can recommend those two solutions:

  • replacing NSFontAttributeName with kCTFontAttributeName since they both have the same value

  • using the same macro you do on lines 510, 521, 537, 549:

    #if  __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
    

Thanks for considering!

podspec

saw you just posted a number of changes, you should bump the podspec version so changes are properly detected for those of us using cocoapods :-)

Issue when configured using auto layout and viewDidLoad

Hi,

Since the release of 1.3 and the introduction of the scrolling capability we're not able to use HMSegmentedControl in combination with auto layout's constraints.

We configure our subviews in viewDidLoad and at that time their frame is not determined yet. We use auto layout constraints to have the subviews automatically placed properly.
The problem is that when HMSegmentedControl sets the frame of self.scrollView (line 257), self.frame.size.width and self.frame.size.height are equal to 0 making the view invisible.

Here's an example of our setup:

- (void)viewDidLoad
{
  [super viewDidLoad];

  HMSegmentedControl *segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:sectionTitles];
  segmentedControl.backgroundColor = [UIColor clearColor];
  segmentedControl.textColor = [UIColor grayColor];
  segmentedControl.font = [UIFont boldSystemFontOfSize:16.0f];

  segmentedControl.selectedTextColor = [UIColor blackColor];
  segmentedControl.selectionIndicatorHeight = 5.0f;
  segmentedControl.selectionIndicatorColor = [UIColor colorWithHex:0x00A5E4];
  segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
  segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleBox;
  segmentedControl.selectedSegmentIndex = 0;

  [self.containerView addSubview:segmentedControl];
  [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[segmentedControl]-0-|"
                                                                             options:0
                                                                             metrics:nil
                                                                               views:@{@"segmentedControl": segmentedControl}]];
  [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[segmentedControl]-0-|"
                                                                             options:0
                                                                             metrics:nil
                                                                               views:@{@"segmentedControl": segmentedControl}]];
}

Note: self.containerView is already a subview of self.view through the storyboard

Touches sometimes not registering

When using this control with other events, sometimes the touches don't register. Possible change

Changing :
UITouch *touch = [[event allTouches] anyObject];
to
UITouch *touch = [touches anyObject];

fixed the issue but haven't tested properly.

Navigation Controller Problem

I am using the segmented control with images and a scroll view (segmented control 4 in the demo) and everything is working perfectly except when i use a navigation controller, the area of the segmented control seem to have bigger content are and i can scroll vertically and move around the segmented control items

Can't scroll scroll view when touch starts from HMSegmentedControl

Hey.

Im using HMSegmentedControl on view with UIScrollView that scrolls content of the view. Everything is working great except I can't scroll view if touch starts from segmented control.

I think segmented control is receiving scroll event but, as it has no use for it, it just ignores it. Is there any way to forward scroll event from HMSegmentedControl to its superview?

Transparent background

Was wondering why I couldn't set background to [UIColor clearColor].
Realized I'd missed setting opaque to NO.

iOS 7 issue: CALayer position contains NaN

HMSegmentetControl.m crashes in drawRect: on the line titleLayer.frame = rect;
when running on iOS 7 preview 2. It seems that rect.origin.x = nan and rect.size.width = inf.

The error message is:
'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 17]'

'setSelectedSegmentIndex' causes TestFlightApp crash

Although my app built & ran without issue on iOS simulator and on my local device using HMSegmentedControl, the app crashed upon launching when the .ipa file was distributed via TestFlightApp.

Turns out the message call 'setSelectedSegmentIndex:0' to the segmented control in [viewDidLoad] was triggering the crash after downloading from TestFlightApp.

Commented that line out and app (& segmented control) functioned fine. Strange.

need better effect

hi,my friend.I notice your Control last year on github and it helps me a lot. thank you for sharing,i like it very much.

i think it can be much better if it has better Interaction design effect. just like NYSegmentedControl on github. while the scrollView didScroll in HMSegmentedControl,the indicatorView changed at once.hm,may be a little difficult to understand....I am sorry that my written English is weak.

haha, thank you for reading my issue.

Can it be used in storyboards & xibs?

I was just trying to get the control to work in a storyboard and I started with an existing UISegmentedControl, then tried to change the classname to HMSegmentedControl, but Interface Builder doesn't seem to like it.

Any suggestions ?

Thanks
Chris

not scrollable when both images and titles

hi,

cool control - good work - thanks!

it was working great when used with images only i.e. it was taking actual image width and enabled horizontal scrolling but when also adding titles, it fits everything into frame width and not allow for scrolling - i set scrollenabled YES and
segmentWidthStyle = HMSegmentedControlSegmentWidthStyleFixed;
etc. but inside code
sectionWidth = MAX(stringWidth, imageWidth)
is not respected and the calculation is off.

in the method

  • (void)updateSegmentsRects
    if ([self sectionCount] > 0) {
    self.segmentWidth = self.frame.size.width / [self sectionCount];
    }
    this above line seems to be making the calculation go wrong
  • seems like scroll enabled being deprecated is causing the problem

could you plz check
thanks

How to Set Segmented Control BackGround Colour when it is Scrolled?

I am Newbie in iOS Development.I use HMSegmentedControll For my Application it Contain Seven Section Title and i want to Change BackGround Colour of my SegmentedControll When it was Swipe to Next Title How it Possible. If it is Possible then Please Give me Solution?

<Error>: CGContextSetStrokeColorWithColor: invalid context 0x0

Environment: Ipad3, ios7

: CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Need to disable scrollsToTop, so it won't interfere with other scroll views

I had to create this category, so it won't interfere with scrollsToTop behaviour of other scroll views being displayed on screen, such as a UITableView.

@implementation HMSegmentedControl (ScrollView)

- (void)disableScrollsToTop
{
    [self disableScrollsToTopForViewAndSubviews:self];
}

- (void)disableScrollsToTopForViewAndSubviews:(UIView *)view
{
    for (UIView *subview in [view subviews]) {
        if ([subview isKindOfClass:[UIScrollView class]]) {
            UIScrollView *scrollView = (UIScrollView *)subview;
            [scrollView setScrollsToTop:NO];
        }

        [self disableScrollsToTopForViewAndSubviews:subview];
    }
}

@end

I can fork and pull request, but I don't think it's necessary in this case. How about setting the self.scrollView.scrollsToTop = NO ?

Want to be able to click on an already selected button

Would like to be able to set a flag that enables determine if the touchesEnded method
will call the setSelectedSegmentIndex method even if the you are touching the already selected index.

Believe it can be achieved by adding a new boolean property and checking it. see below.

  • (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInView:self];

    if (CGRectContainsPoint(self.bounds, touchLocation)) {
    NSInteger segment = (touchLocation.x + self.scrollView.contentOffset.x) / self.segmentWidth;

    // change this to 
    //if (segment != self.selectedSegmentIndex) {
    //    [self setSelectedSegmentIndex:segment animated:YES notify:YES];
    //}
    

    // to this
    if (okToTouchSelectedIndex) {
    [self setSelectedSegmentIndex:segment animated:YES notify:YES];
    }

    }
    }

Horizontal scrolling

Hello,

I would like to enable horizontal scrolling anywhere in my view to change selected index of the HMSegmentedControl. Is it possible ?

Thank you

PS: Sorry I'm not english

Why the use of Storyboard have a problem?

I drag and drop a View on ViewController,Added a IBOutlet,use code:

    [self.segmentControl setSectionTitles:@[@"Worldwide", @"Local", @"Headlines",@"aav"]];
    //    [self.segmentControl setSelectedSegmentIndex:1];
    [self.segmentControl setBackgroundColor:[UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1]];
    [self.segmentControl setTextColor:[UIColor whiteColor]];
    [self.segmentControl setSelectedTextColor:[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1]];
    [self.segmentControl setSelectionIndicatorColor:[UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1]];
    [self.segmentControl setSelectionStyle:HMSegmentedControlSelectionStyleBox];
    [self.segmentControl setSelectionIndicatorLocation:HMSegmentedControlSelectionIndicatorLocationUp];

It doesn't work, how to solve?

Seperator line at the bottom

can you set a property that a Seperator line at the bottom of segment (which we can set the Seperator line is hidden and the color of the Seperator line)?

*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]

Hello, I'm expiriencing crashes with following error:

*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]

the stack trace is here:

0   CoreFoundation  <redacted> + 130    
1   libobjc.A.dylib objc_exception_throw + 38   
2   CoreFoundation  <redacted> + 176    
3   VLPush  -[HMSegmentedControl frameForSelectionIndicator] (HMSegmentedControl.m:233) + 3038043   
4   VLPush  -[HMSegmentedControl setSelectedSegmentIndex:animated:notify:] (HMSegmentedControl.m:392) + 3041749 
5   VLPush  -[HMSegmentedControl touchesEnded:withEvent:] (HMSegmentedControl.m:315) + 3040615  
6   VLPush  -[HMScrollView touchesEnded:withEvent:] (HMSegmentedControl.m:51) + 3033051 
7   UIKit   <redacted> + 528    
8   UIKit   <redacted> + 758    
9   UIKit   <redacted> + 196    
10  UIKit   <redacted> + 7102   
11  CoreFoundation  <redacted> + 14 
12  CoreFoundation  <redacted> + 206    
13  CoreFoundation  <redacted> + 622    
14  CoreFoundation  CFRunLoopRunSpecific + 522  
15  CoreFoundation  CFRunLoopRunInMode + 106    
16  GraphicsServices    GSEventRunModal + 138   
17  UIKit   UIApplicationMain + 1136    
18  VLPush  main (main.m:16) + 144487   
19  libdyld.dylib   <redacted> + 2

my use case is always the same, I have 3 tabs. Any help is appreciated!

Have a nice day

Redrawing HMSegmentedControl

I am using HMSegmentedControl as an IBOutlet in a UIView. Therefore, I cannot programmatically init the control, which seems to be the only way to set the images for the segments. I have tried everything I can think of to set the segments after the control has been initialized, but it seems that it must be done on initialization. Is there another way that you have provided?

selectedSegmentIndex not work

Hello, I have a problem with selectedSegmentIndex, since for more than change the value to 0 or 2, for example, always shows me the contents of one selectedSegmentIndex
Do not understand why ...

self.segmentedControl4 = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(53, 300 + yDelta, 918, 50)];
self.segmentedControl4.sectionTitles = @[@"Información", @"Trailer", @"Comentarios", @"Enlaces"];
self.segmentedControl4.selectedSegmentIndex = 0;
self.segmentedControl4.backgroundColor = [UIColor clearColor];

In the example also HMSegmentedControlExample.xcodeproj so with the segmentedControl4.

Thanks for any help.

Selected Index Issue

Say you have two segments. It is possible in the simulator, when you click on the rightmost pixel of the control, to have it setSelectedIndex to 3. I'm not especially familiar with the code base, but I was able to prevent this behavior by checking whether the selected segment number is greater than [sectionTitles count].

HMSegmentedControl.m

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
...
        if(segment < [self.sectionTitles count])
        {
            if (segment != self.selectedSegmentIndex) {
                [self setSelectedSegmentIndex:segment animated:YES notify:YES];
            }
        }
...
}

Why my "pod search HMSegmentedControl" is still version 1.3.0?

➜  ~  pod search HMSegmentedControl


-> HMSegmentedControl (1.3.0)
   A drop-in replacement for UISegmentedControl mimicking the style of the one
   in Google Currents and various other Google products.
   pod 'HMSegmentedControl', '~> 1.3.0'
   - Homepage: https://github.com/HeshamMegid/HMSegmentedControl
   - Source:   https://github.com/HeshamMegid/HMSegmentedControl.git
   - Versions: 1.3.0, 1.2.0, 1.1.0, 1.0.0 [master repo]

OSX : 10.9.5

Cocoapods Version:

➜  ~  pod --version
0.33.1

Any ideas? Thanks in advance:]

Vertical centering

Sorry for not creating a proper pull request.

Current code [line 166]:
CGFloat y = roundf(((CGRectGetHeight(self.frame) - self.selectionIndicatorHeight) / 2) + (self.selectionIndicatorHeight - stringHeight / 2));

should be:
CGFloat y = roundf(((CGRectGetHeight(self.frame) - self.selectionIndicatorHeight) / 2) + (self.selectionIndicatorHeight - stringHeight) / 2);

note the closing ')'

Crash on iOS 6 Simulator

This line causing crash in iOS 6 simulator, because following code is wrong (__IPHONE_7_0 is defined, but it doesn't mean that iOS7 is used!)

 #ifdef __IPHONE_7_0
            CGFloat stringWidth = [titleString sizeWithAttributes:@{NSFontAttributeName: self.font}].width + self.segmentEdgeInset.left + self.segmentEdgeInset.right;
 #else
            CGFloat stringWidth = [titleString sizeWithFont:self.font].width + self.segmentEdgeInset.left + self.segmentEdgeInset.right;
 #endif

I change it too this
#define IS_OS_7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
CGFloat stringWidth;
if (IS_OS_7_OR_LATER)
{
stringWidth = [titleString sizeWithAttributes:@{NSFontAttributeName: self.font}].width + self.segmentEdgeInset.left + self.segmentEdgeInset.right;
}
else
{
stringWidth = [titleString sizeWithFont:self.font].width + self.segmentEdgeInset.left + self.segmentEdgeInset.right;
}

line 535 warning in .m file

I got a warning of "Code will never be executed" in .m file, line 535, while using in Swift .

    } else if (self.type == HMSegmentedControlTypeTextImages && HMSegmentedControlSegmentWidthStyleFixed){

I wonder should it be like this:

    } else if (self.type == HMSegmentedControlTypeTextImages && self.segmentWidthStyle == HMSegmentedControlSegmentWidthStyleFixed){

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.