• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sindresorhus/CustomButton: Customizable button for your macOS app

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

sindresorhus/CustomButton

开源软件地址(OpenSource Url):

https://github.com/sindresorhus/CustomButton

开源编程语言(OpenSource Language):

Swift 100.0%

开源软件介绍(OpenSource Introduction):

CustomButton

Customizable button for your macOS app

It's a layer-based NSButton subclass that animates the styles and colors between normal and active (pressed) state.

This package is used in production by Gifski.

Requirements

  • macOS 10.12+
  • Xcode 13+
  • Swift 5.5+

Install

Add https://github.com/sindresorhus/CustomButton in the “Swift Package Manager” tab in Xcode.

Usage

See the source for what properties you can change and play with it in the example app. By default, it has no style.

import Cocoa
import CustomButton

@main
final class AppDelegate: NSObject, NSApplicationDelegate {
	@IBOutlet weak var window: NSWindow!

	func applicationDidFinishLaunching(_ notification: Notification) {
		let button = CustomButton()
		button.translatesAutoresizingMaskIntoConstraints = false
		button.title = "CustomButton"
		button.activeBackgroundColor = .systemPink
		button.borderWidth = 1
		button.borderColor = .systemPink
		button.cornerRadius = 5
		button.textColor = .systemPink
		button.activeTextColor = .white

		let contentView = window.contentView!
		contentView.addSubview(button)

		NSLayoutConstraint.activate([
			button.centerXAnchor.constraint(equalTo: contentView.centerXAnchor),
			button.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
			button.widthAnchor.constraint(equalToConstant: 100),
			button.heightAnchor.constraint(equalToConstant: 30)
		])
	}
}

The button can also be edited in Interface Builder, but Xcode is very buggy with @IBDesignable, so I would recommend using it only programmatically for now.

FAQ

Can you support Carthage and CocoaPods?

No, but you can still use Swift Package Manager for this package even though you mainly use Carthage or CocoaPods.

Won't SwiftUI make this moot?

SwiftUI does indeed make it much easier to create custom-looking buttons, but SwiftUI is still immature and most companies will not be able to require macOS 10.15 for a long time. So this package will still be useful for multiple years to come.

Related

You might also like my apps.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap