- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
最佳答案
代码
extension UIView {
///Add border color with corners
func addBorderWithColor(color: UIColor, roundingCorners: UIRectCorner) {
self.layer.borderWidth = 1
self.layer.borderColor = color.CGColor
self.addRoundingCorners(roundingCorners)
}
///Use corner radius depending on UIRectCorner
private func addRoundingCorners(roundingCorners: UIRectCorner) {
let path = UIBezierPath(roundedRect:self.bounds, byRoundingCorners:roundingCorners, cornerRadii: CGSizeMake(4, 4))
let maskLayer = CAShapeLayer()
maskLayer.path = path.CGPath
self.layer.mask = maskLayer
}
}
let segmentedControl = UISegmentedControl(items: ["Red", "Green", "Blue"])
segmentedControl.subviews[0].addBorderWithColor(UIColor.blueColor(), roundingCorners: [.TopRight, .BottomRight])
segmentedControl.subviews[1].addBorderWithColor(UIColor.greenColor(), roundingCorners: [])
segmentedControl.subviews[2].addBorderWithColor(UIColor.redColor(), roundingCorners: [.TopLeft, .BottomLeft])
segmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor()], forState: UIControlState.Normal)
Playground
代码
let segmentedControl = UISegmentedControl(items: ["Red", "Green", "Blue"])
//Change Text Attributes (Changing textColor to black)
//**Be sure to manage all the UIControlState for these attributes if you need to customize this for other states
segmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor()], forState: UIControlState.Normal)
//Change tintColor to clear, in order to set border invisible
segmentedControl.tintColor = UIColor.clearColor()
Playground
答案是NO
您无法移除 UISegmentedControl
您可以通过使用 UIButton
创建自定义控件来实现您正在寻找的内容。
在UISegmentedControl
状态下,可以去掉UISegmentedControl
中item之间的分隔符,也可以改变tintColor(borderColor)
关于ios - 如何从 UISegmentController 中删除边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34334967/
我有一个 tableView。我按如下方式注册 Cell: tableView.register(TVCellElementProperties.self, forCellReuseIdentifie
我的项目有 UISegmentController。我有灰色的颜色分离器。 黑线之间是分隔符,有白色分隔符,但我想要灰色分隔符?请建议一些代码。我的代码是 - (void)changeColor{
在我的 viewDidLoad 中,我正在检索用户首选项并更新设置选项卡。它适用于 editSelection (参见代码),但其他的 NSUserDefaults *userDefaults =
我有一个 UIPageViewController,我有 4 个页面。我的其中一个页面有 UISegmentControl,用户可以在其中点击或滑动页面来更改段。我认为它在 UIPageControl
我有一个带有黑色色调的 UISegmentedControl ,因此所选元素在视觉上与其他元素没有什么不同,因为 iOS 使所选项目变暗,因此黑色保持不变。有谁知道如何在不使用未记录的方法的情况下使所
我有一个 TableView ,它有一个段 Controller ,它分别有两个段类别 1 和 2。当我将一个项目添加到类别 1 时,它完美地完成了,但是当我将一个项目添加到类别 2 时,它使应用程序
我将分段控件用作选项卡栏 Controller 的子选项卡。我在主选项卡上有一个按钮,它应该转换到第二个选项卡(带有子选项卡的那个)并以编程方式将 UISegmentedControl 切换到第一个选
我有一个分段控件来定义准备食谱的难度级别。我需要在一个我不会对其进行编辑的配方中加载赋值。遵循代码: @IBOutlet var segNewDifficultyLevel: UISegmentedC
我有一个名为 mySegmentedControl 的 UISegmentedControl @property (nonatomic) IBOutlet UISegmentedControl *my
我想知道如何通过 UISegmentController 正确操作两个 View 。 现在我有两个 UIViews 和 UISegmentController 以及过程 changeView: - (
我想移除 UISegmentController 的边框。如果有可能。否则将其更改为自定义边框颜色。 最佳答案 更新 案例一——自定义segmentedControl中各元素的borderColor
如何在 swift 中更改 segmentController 的索引。我希望单击按钮时应更改段索引的值 func respondToGesture(sender: UIGestureRecogni
如何在 UINavigationItem 中添加 UISegmentedControl?我想创建一个带有段控件的 UINavigationBar,它添加在导航栏的标题中。 UISegmentedCon
我有一个父类 A,它有两个容器 B 和 C,以及两个各自的 uiviewcontroller。我正在使用 UISegmentContol 切换两个 Controller 。父类有一个对象“Variab
我已经在网上搜索过了,但仍然不知道该怎么做。 基本上我想在导航栏下方放置一个带有 3 个按钮的分段控制栏。当用户单击分段控件中的按钮时,它将循环显示 TableView 、日历和 GridView 。
我无法在我的 UISegmentController 中选择索引。我可以通过模拟器手动触摸,我可以通过代码设置 selectedSegmentIndex,但我无法让它在模拟器中显示我通过代码设置的索引
我尝试将 UISegmentControl 集成到我的应用程序中,它应该只显示当前状态。这意味着我不希望 SegmentControl 是可触摸的。 我试过: passwdStrength = (UI
我有一个 UISegmentedControl 的子类,在 Cocoa Touch 类中称为 SegControl。 class SegControl: UISegmentedControl { ov
这是我目前使用的代码。不幸的是,UISegmentControl 不是栏的最大宽度。有没有一种快速简便的方法可以使其成为代码中的最大宽度,而无需将其设置为精确的框架宽度? UIBarButto
我在我的 iPhone 应用程序中以编程方式设置 UISegmentControl。默认情况下它有 2 个段。在我的代码中,我填充了两个以上的段。我该如何设置,有帮助吗? 更新 我的问题是如何通过代码
我是一名优秀的程序员,十分优秀!