自定义 Swift 版 SegmentControl,可以动态调节 segment 宽度,滚动调节位置,选择红点展示

bbsc5977 5年前
   <h2><strong>JTSegmentControl</strong></h2>    <p>自定义SegmentControl,可以选择红点、动态调节segment宽度,以及滚动。</p>    <h2><strong>Display</strong></h2>    <p style="text-align:center"><img src="https://simg.open-open.com/show/4f561ad9f8bcb971e6efce365a41a191.gif"> <img src="https://simg.open-open.com/show/1cb79471b0d56b386f6fe1a2aee3b503.gif"></p>    <h2><strong>Usage</strong></h2>    <p>Simple init JTSegmentControl</p>    <pre>  <code class="language-swift">var frame = CGRect(x: 10.0, y: 130.0, width: self.view.bounds.size.width - 20.0, height: 44.0)          let segmentControl = JTSegmentControl(frame: frame)          segmentControl.delegate = self          segmentControl.items = ["first", "second", "third", "fouth"]          segmentControl.showBridge(show: true, index: 1)          segmentControl.autoScrollWhenIndexChange = false          view.addSubview(segmentControl)</code></pre>    <p>Width is divide equally . This is have bridge and not scrolling when index changed.(宽度根据bounds进行平分,展示红点,选择item的时候不自动调整位置)</p>    <p>Init JTSegmentControl,auto to set itemView's width in scrollView, scrolling when index changed.(在一个ScrollView里,根据内容自动调整每个item的宽度,同时,选择item的时候自动调整它的位置。)</p>    <pre>  <code class="language-swift">frame = CGRect(x: 10.0, y: 250.0, width: self.view.bounds.size.width - 20.0, height: 44.0)          let autoWidthControl = JTSegmentControl(frame: frame)          autoWidthControl.delegate = self          autoWidthControl.items = ["first", "second", "third", "fouth", "fifth", "sixth", "seventh", "eighth"]          autoWidthControl.selectedIndex = 1          autoWidthControl.autoAdjustWidth = true          autoWidthControl.bounces = true          view.addSubview(autoWidthControl)</code></pre>    <p>JTSegmentControl Delegate</p>    <pre>  <code class="language-swift">func didSelected(segement: JTSegmentControl, index: Int)</code></pre>    <h2><strong>Also you can custom</strong></h2>    <pre>  <code class="language-swift">// JTSegmentPattern.swift      static let itemTextColor      static let itemSelectedTextColor        static let itemBackgroundColor      static let itemSelectedBackgroundColor        //MARK - Text font      static let textFont      static let selectedTextFont        //MARK - slider      static let sliderColor      static let sliderHeight        //MARK - bridge      static let bridgeColor</code></pre>    <h2><strong>Author</strong></h2>    <p>JT. Guangzhou_xia</p>    <h2><strong>License</strong></h2>    <p>JTSegmentControl is Available under the MIT license.</p>    <p> </p>    <p>来自:https://github.com/guangzhouxia/JTSegmentControl</p>    <p> </p>