• Stars
    star
    946
  • Rank 48,319 (Top 1.0 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 15 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A UIButton subclass that works with for non-rectangular button shapes.

OBShapedButton

OBShapedButton is a UIButton subclass optimized for non-rectangular button shapes. Instances of OBShapedButton respond to touches only in areas where the image that is assigned to the button for UIControlStateNormal is non-transparent.

How to Install

Installation via CocoaPods

If possible, you should install OBShapedButton via CocoaPods:

$ edit Podfile
platform :ios
pod 'OBShapedButton'

Manual Installation

If you cannot use CocoaPods for whatever reason, manually add OBShapedButton.h, OBShapedButton.m, UIImage+ColorAtPixel.h, and UIImage+ColorAtPixel.m to your Xcode project.

Usage

  • Design your UI in Interface Builder with UIButtons as usual. Set the Button type to Custom and provide transparent PNG images for the different control states as needed.
  • In the Identity Inspector in Interface Builder, set the Class of the button to OBShapedButton. That's it! Your button will now only respond to touches where the PNG image for the normal control state is non-transparent.

Credits

Written by Ole Begemann, [email protected]
http://oleb.net/blog/2009/10/obshapedbutton-non-rectangular-buttons-on-the-iphone/
October, 2009

Corrected some serious bugs in April 2011. Thanks to the commenters on my blog and those who posted issues on GitHub for pointing them out, including the fixes.

Contributors:

  • balabhadra added support for background images.
  • yurkins fixed an issue that only occurred in release builds.
  • Steven Zweier fixed an issue that would intermittently result in wrong hit tests.
  • jvanakker fixed an issue with images that had a different size than the button.

MIT License

Copyright (c) 2009 Ole Begemann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

whats-new-in-swift-4

An Xcode playground showcasing the new features in Swift 4.0.
Swift
1,827
star
2

whats-new-in-swift-4-2

An Xcode playground demonstrating the new features in in Swift 4.2.
Swift
872
star
3

OLEContainerScrollView

A UIScrollView subclass that intelligently handles multiple child scroll views and does not interfere with UIKitสผs cell reuse functionality.
Objective-C
588
star
4

Animated-Paths

Demo project: Animating the drawing of a CGPath with CAShapeLayer.strokeEnd
Objective-C
505
star
5

swiftui-view-lifecycle

Observe how different SwiftUI container views affect state and lifecycle events (onAppear, onDisappear).
Swift
374
star
6

OBSlider

A UISlider subclass that adds variable scrubbing speeds (as seen in the Music app on iOS).
Objective-C
267
star
7

CollectionViewParallaxScrolling

A custom UICollectionViewFlowLayout to support parallax scrolling in cells. Check out the accompanying blog post for more info.
Objective-C
250
star
8

Ampere

Adding multiplication and division to the units of measurement types in Foundation.
Swift
171
star
9

swiftui-layout-inspector

A tool for learning how the SwiftUI layout system works, and for debugging your own layout code.
Swift
168
star
10

SortedArray

An array that keeps its elements sorted according to a given sort predicate.
Swift
165
star
11

CustomScrollView

A very simple implementation of a scroll view on iOS. Not meant for production, just for learning purposes. Please check out the accompanying blog post.
Objective-C
154
star
12

OBGradientView

A simple UIView wrapper for CAGradientLayer. For the times when it's more convenient to use a view instead of a CALayer.
Objective-C
112
star
13

NSBundle-OBCodeSigningInfo

Check an app bundle's code signing and sandboxing state to NSBundle.
Objective-C
106
star
14

swift-rp-pico-bare

Embedded Swift on the Raspberry Pi Pico without the Pico C/C++ SDK
C
93
star
15

Storyboard-Strings-Extraction

Automatically extract translatable strings from Xcode storyboards and update .strings files.
Shell
74
star
16

SilentPush

An iOS test app for testing silent push notifications and background fetching.
Swift
71
star
17

CGPathHitTesting

A demo iOS app to illustrate hit testing with CGPathCreateCopyByStrokingPath()
Objective-C
71
star
18

pico-embedded-swift

Embedded Swift on the Raspberry Pi Pico
CMake
62
star
19

AppointmentList

Sample iOS app that lists events from the device's calendar store in a table view and groups them by date.
Objective-C
48
star
20

RemoteViewControllers

Introspection of the private and undocumented remote view controllers feature in iOS 6
Objective-C
45
star
21

iphone-6-plus-rendering

Quick and dirty test apps to understand how the built-in downsampling to screen resolution works on the iPhone 6 Plus.
Swift
44
star
22

GestureRecognition

Sample iOS app for a blog post about gesture recognition and attention to detail
Objective-C
42
star
23

itunesconnect-financialreports

Converts Financial Reports from iTunes Connect (App Store) to HTML
Ruby
37
star
24

OSLogStoreTest

Test app for evaluating if apps can access their own OSLog logs via OSLogStore.
Swift
30
star
25

AnalogDial

A circular analog dial that can display a numeric value in a specified range (like an analog speedometer).
Swift
24
star
26

AppleCoreDataModels

21
star
27

NotificationUnregistering

Testing the behavior of the block based NotificationCenter API. Do you have to call NotificationCenter.removeObserver(_:) or is it enough to let the observer token go out of scope? Turns out: the former (tested on iOS 11.2).
Swift
16
star
28

ConcurrencyBenchmark

Swift
15
star
29

HexHexHex

A parser for the Intel Hexadecimal Object File Format (.hex), written in Swift.
Swift
14
star
30

Kaffeekasse

Sample apps for a Passbook tutorial on my blog.
C++
14
star
31

transcribe

A Swift parser for output files from automated transcription services. An experiment inspired by the Swift Community Podcast.
Swift
13
star
32

Picobello

An assembler for the Microchip PIC instruction set, written in Swift.
Swift
13
star
33

topaz

An attempt to reimplement a minimal version of the Swift standard library. Just for fun โ€” I doubt this has practical applications.
Swift
12
star
34

RGBtoCMYK

A simple command-line Cocoa app to convert images to CMYK
Objective-C
10
star
35

SwiftUI-Mac-Focus

Test project for playing with focus, keyboard shortcuts, menu commands in SwiftUI on the Mac
Swift
10
star
36

CAShapeLayer-Animation

Demo project for a Stack Overflow question: "Animate CAShapeLayer path on animated bounds change"
Objective-C
9
star
37

Funtime

A Swift interface for the Objective-C Runtime API
Swift
8
star
38

CollectionViewContentSizeAnimation

Demo project for a Stack Overflow question.
Objective-C
8
star
39

SwiftPM-embedded-minimal

Swift
6
star
40

OBStack

OBStack is a very simple implementation of a stack data structure (last in, first out) in Cocoa.
Objective-C
5
star
41

AsyncSequenceOperators

Experimental reimplementations of functional reactive operators for AsyncSequence. DO NOT USE IN PRODUCTION!
Swift
5
star
42

AsyncXMLParsing

An AsyncSequence wrapper for Foundationโ€™s XMLParser (experimental)
Swift
4
star
43

SwiftUIAnimationBug

https://twitter.com/olebegemann/status/1587912494290444290
Swift
3
star
44

twitter-backup

A Ruby script to backup tweets (in the raw JSON format)
Ruby
3
star
45

rust-rp-pico-template

A cargo-generate template for embedded Rust development on the Raspberry Pi Pico.
Rust
2
star
46

docopt.objc

Incomplete beginnings of an implementation of the docopt language in Objective-C.
Objective-C
2
star
47

CoreDataDebugging

Swift
2
star
48

SetSolver

A solver for the card game Set.
Swift
1
star
49

SwiftConcurrencyDeadlock

Swift
1
star