Skip to content

Commit

Permalink
Merge pull request #98 from mattrubin/core-graphics-sugar
Browse files Browse the repository at this point in the history
Modernize CoreGraphics methods
  • Loading branch information
mattrubin committed Jan 31, 2016
2 parents 501b327 + 8a3b376 commit 3ce2ba9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 40 deletions.
31 changes: 16 additions & 15 deletions Authenticator/Source/OTPProgressRing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
// OTPProgressRing.swift
// Authenticator
//
// Copyright (c) 2014 Matt Rubin
// Copyright (c) 2014-2015 Authenticator authors
//
// 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:
// 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.
// 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.
//

import UIKit
Expand Down Expand Up @@ -53,9 +54,9 @@ class OTPProgressRing: UIView {

CGContextSetStrokeColorWithColor(context, self.tintColor.CGColor)
CGContextAddArc(context,
CGRectGetMidX(ringRect),
CGRectGetMidY(ringRect),
CGRectGetWidth(ringRect)/2,
ringRect.midX,
ringRect.midY,
ringRect.width/2,
CGFloat(-M_PI_2),
CGFloat(2 * M_PI * self.progress - M_PI_2),
1)
Expand Down
37 changes: 20 additions & 17 deletions Authenticator/Source/ScannerOverlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
// ScannerOverlayView.Swift
// Authenticator
//
// Copyright (c) 2013 Matt Rubin
// Copyright (c) 2013-2015 Authenticator authors
//
// 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:
// 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.
// 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.
//

import UIKit
Expand All @@ -43,12 +44,14 @@ class ScannerOverlayView: UIView {
UIColor(white: 0, alpha: 0.5).setFill()
UIColor(white: 1, alpha: 0.2).setStroke()

let smallestDimension = min(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))
let smallestDimension = min(self.bounds.width, self.bounds.height)
let windowSize = 0.9 * smallestDimension
let window = CGRectMake(CGRectGetMidX(rect) - windowSize/2,
CGRectGetMidY(rect) - windowSize/2,
windowSize,
windowSize)
let window = CGRect(
x: rect.midX - windowSize/2,
y: rect.midY - windowSize/2,
width: windowSize,
height: windowSize
)

CGContextFillRect(context, rect)
CGContextClearRect(context, window)
Expand Down
5 changes: 4 additions & 1 deletion Authenticator/Source/SegmentedControlRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ class SegmentedControlRowCell<Action>: UITableViewCell {

override func layoutSubviews() {
super.layoutSubviews()
segmentedControl.frame = CGRectMake(20, 15, CGRectGetWidth(contentView.bounds) - 40, 29)

let margin: CGFloat = 20
let width = contentView.bounds.width - (2 * margin)
segmentedControl.frame = CGRect(x: margin, y: 15, width: width, height: 29)
}

// MARK: - View Model
Expand Down
6 changes: 4 additions & 2 deletions Authenticator/Source/TextFieldRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ class TextFieldRowCell<Action>: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()

textLabel?.frame = CGRectMake(20, 15, CGRectGetWidth(contentView.bounds) - 40, 21)
textField.frame = CGRectMake(20, 44, CGRectGetWidth(contentView.bounds) - 40, 30)
let margin: CGFloat = 20
let width = contentView.bounds.width - (2 * margin)
textLabel?.frame = CGRect(x: margin, y: 15, width: width, height: 21)
textField.frame = CGRect(x: margin, y: 44, width: width, height: 30)
}

// MARK: - View Model
Expand Down
8 changes: 4 additions & 4 deletions Authenticator/Source/TokenListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TokenListViewController: UITableViewController {
}

private var displayLink: CADisplayLink?
private let ring: OTPProgressRing = OTPProgressRing(frame: CGRectMake(0, 0, 22, 22))
private let ring: OTPProgressRing = OTPProgressRing(frame: CGRect(x: 0, y: 0, width: 22, height: 22))
private lazy var noTokensLabel: UILabel = {
let noTokenString = NSMutableAttributedString(string: "No Tokens\n",
attributes: [NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 20)!])
Expand Down Expand Up @@ -86,9 +86,9 @@ class TokenListViewController: UITableViewController {
self.navigationController?.toolbarHidden = false

// Configure "no tokens" label
self.noTokensLabel.frame = CGRectMake(0, 0,
self.view.bounds.size.width,
self.view.bounds.size.height * 0.6)
self.noTokensLabel.frame = CGRect(x: 0, y: 0,
width: self.view.bounds.size.width,
height: self.view.bounds.size.height * 0.6)
self.view.addSubview(self.noTokensLabel)

// Update with current viewModel
Expand Down
2 changes: 1 addition & 1 deletion Authenticator/Source/TokenRowCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TokenRowCell: UITableViewCell {
passwordLabel.frame.origin.y += 20
passwordLabel.frame.size.height -= 30

nextPasswordButton.center = CGPointMake(CGRectGetMaxX(fullFrame) - 25, CGRectGetMidY(passwordLabel.frame))
nextPasswordButton.center = CGPoint(x: fullFrame.maxX - 25, y: passwordLabel.frame.midY)
}


Expand Down

0 comments on commit 3ce2ba9

Please sign in to comment.