Giter Club home page Giter Club logo

smsegmentview's Introduction

SMSegmentView Description

  • Custom segmented control for iOS.
  • Written in Swift.
  • Support both images and text.
  • Support vertically organise segments.
  • More customisible than UISegmentedControl and easy to expand (e.g. styling).

For CocoaPods User

Add pod 'SMSegmentView', '~> [VERSION]' to Podfile.

How To Use

Step 1

Drag SMSegmentView.swift and SMSegment.swift into your Xcode project.

Step 2

Initialise SMSegmentView: You can simply use SMSegmentView(frame:) to initialise your segment view by using the default properties. But mostly, you may want to use SMSegmentView(frame:, dividerColour:, dividerWidth:, segmentAppearance:) to make it look more customised. The parameter segmentAppearance: reads a SMSegmentAppearance instance. You can find what attributes it supports in SMSegmentAppearance class.

E.g.:

let appearance = SMSegmentAppearance()
appearance.segmentOnSelectionColour = UIColor(red: 245.0/255.0, green: 174.0/255.0, blue: 63.0/255.0, alpha: 1.0)
appearance.segmentOffSelectionColour = UIColor.whiteColor()
appearance.titleOnSelectionFont = UIFont.systemFontOfSize(12.0)
appearance.titleOffSelectionFont = UIFont.systemFontOfSize(12.0)
appearance.contentVerticalMargin = 10.0

let segmentView = SMSegmentView(frame: SomeFrame, dividerColour: UIColor(white: 0.95, alpha: 0.3), dividerWidth: 1.0, segmentAppearance: appearance)

Step 3

Add action for UIControlEvents.ValueChanged, and implement the action method.

E.g. segmentView.addTarget(self, action: #selector(YourViewController.selectSegmentInSegmentView(_:)), forControlEvents: .ValueChanged)

Step 4

Add segments to your segment view.

E.g.:

segmentView.addSegmentWithTitle("Segment 1", onSelectionImage: UIImage(named: "target_light"), offSelectionImage: UIImage(named: "target"))
segmentView.addSegmentWithTitle("Segment 2", onSelectionImage: UIImage(named: "handbag_light"), offSelectionImage: UIImage(named: "handbag"))
segmentView.addSegmentWithTitle("Segment 3", onSelectionImage: UIImage(named: "globe_light"), offSelectionImage: UIImage(named: "globe"))

Optional Step

You can programmatically select/deselect a segment by assign an integer to selectedSegmentIndex.

Support Vertical Mode

You can organise all segments vertically by setting the organiseMode as .Vertical. It is set to .Horizontal by default.

E.g. segmentView.organiseMode = .Vertical

More Info

The framework comes with a sample project to demonstrate how to use it. Besides, this tutorial may give you some idea on how to expand this framework a little bit.

Screenshots

smsegmentview's People

Contributors

b3ll avatar michallaskowski avatar sima-11 avatar tarigancana avatar yhirano 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

smsegmentview's Issues

SMSegment does not handle touchesCancelled properly

The SMSegment view handles touchesBegan and touchesEnded, but touchesCancelled is missing. When adding this component in a scrollView, if you touch down on a segment and start scrolling the scrollView, the segment stays highlighted.

A workaround is to add the following extension to the project:

extension SMSegment {
    open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
        backgroundColor = isSelected ? self.appearance?.segmentOnSelectionColour : self.appearance?.segmentOffSelectionColour
    }
}

touchesBegan and touchesEnded

I can't launch the demo because of this error. That's a shame because your segment view seems really promising and nice looking, thanks for sharing it ;)

capture d ecran 2015-04-28 a 14 37 49

Support multiple touches?

Hi, your control works great (in 2021!), but I'd like to be able to select a segment multiple times -- I am thinking of using a segment to zoom in and another to zoom out. Is this possible?

How can I enable multiple segments to be selected?

Can uh plzz me out, I have designed a vertical UISegmentedControl, But labels inside the segments was no getting size accordingly after rotation. Now when I got solution for my vertical segmented control now Im stuck with this problem.

Supports iOS 7

Hi, this library is write in Swift 3, but Swift 3 dosen't supports iOS 7 right?

didSelectSegmentAtindex

HI great project, but i have a problem.
I copy your code from my project and i put the segment on mapkit, and when i click in segment, method didSelectSegmentAtIndex, it is not called.

I update xcode from 7.3

Unable to run on the devices

Integrating this framework and running it on the simulator works fine without any issue.

But running the same on the real device does not work at all, it gives me an error. Below is the error:

SMSegmentView.framework: bundle format unrecognized, invalid, or unsuitable
Command /bin/sh failed with exit code 1

Support of multiple selections

Hey,

I have just started to use the SMSegmentView library and it's really great, so first of all thanks for such a great work so far!
Do you think if it's possible to add the support of multiple selections to the library?
I think it would be really helpful to have it such thing like in the WLSegmentedControls

Cheers,
Adam

Can't use SMSegmentAppearance in Objective-C project

How to add SMSegmentAppearance in objective c code? I am not getting any options for it.

SMSegmentView(frame: SomeFrame, dividerColour: UIColor(white: 0.95, alpha: 0.3), dividerWidth: 1.0, segmentAppearance: appearance)

The above initialiser is not available when used in objective c code.

About SMSegmentViewDelegate

Hi Author,

I use and love your work. Problem I have with the update for swift 3 is that "SMSegmentViewDelegate" error - undeclared type.

This also happens when I try to manually use the framework.

Can you somehow give me an idea what cause this, been looking and troubled for 2 days.

Hope you could help.

Thanks,

Corner Radius

I tried to add corner radius to SegmentView. It make round corners of whole SegmentView. Is there any way to make round corners of selected segment ?

SMSegmentViewDelegate error

i have the following:

screen shot 2016-02-11 at 22 30 56

but have added:

func segmentView(segmentView: SMSegmentView, didSelectSegmentAtIndex index: Int) {
    print(index)
}

any ideas?

can't override resetContentFrame()

Any reason why resetContentFrame () is marked as private in SMSegment? There is no way to subclass it or any of its subclasses and relayout the various components. I could override layoutSubview but many of the properties are marked private too, such as imageView which makes even overriding layoutSubviews pretty useless.

I would like to draw the text over the image, both centered, and I cannot.

Horizontal Seg with icon on top of title

Hey, thanks for the great seg. Was just wondering if you were planning on adding the functionality of allowing the icon to be above the title? As in a horizontal seg controller but with icon on top of the title. Thanks!

Title below image

Hello,
First of all thank You for making this library. I needed to put both title and image there and you saved me! But the text I want to put in is too long to be displayed next to the image. Are you planning to make text below Image possible? It would really help me

Thanks again,
Filip

Implement initWithCoder method

This is a awesome component! But I can't initialize it from the Interface Builder because initWithCoder is not implemented.
This is a weird behavior because the SMSegmentView class has properties marked as IBInspectable.

Error with crash log

Hello,

I published my app, but it had refused.
When I symbolicate the crash log, I have this line on the exception code ๐Ÿ‘

SMSegment.(title.materializeForSet).(closure #1) (in Honi) (SMSegment.swift:61)

I don't understand, maybe help me please before I post again my app.
Because all test on all device works with TestFlight, so I was surprised by Apple, they say to me "Crash on launch"

Thanks

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.