Skip to content

Commit

Permalink
Merge pull request #10 from daisuke0131/develop
Browse files Browse the repository at this point in the history
version 1.0.6 release.
  • Loading branch information
daisuke0131 committed Oct 2, 2015
2 parents a290513 + ca01918 commit c239c7d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
16 changes: 14 additions & 2 deletions Source/InfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class InfoView: UIView {
let height:UILabel
let bkColor:UILabel
let fontSize:UILabel
let fontColor:UILabel
let margin:CGFloat = 22.0

var targetView:AnyObject?{
Expand All @@ -24,13 +25,15 @@ class InfoView: UIView {
height.text = "height:None"
bkColor.text = "background:None"
fontSize.text = "fontSize:None"
fontColor.text = "fontColor:None"

x.font = UIFont.systemFontOfSize(11)
y.font = UIFont.systemFontOfSize(11)
width.font = UIFont.systemFontOfSize(11)
height.font = UIFont.systemFontOfSize(11)
bkColor.font = UIFont.systemFontOfSize(11)
fontSize.font = UIFont.systemFontOfSize(11)
fontColor.font = UIFont.systemFontOfSize(11)

let window = UIApplication.sharedApplication().keyWindow
//coordinate conversion
Expand All @@ -48,8 +51,13 @@ class InfoView: UIView {
}

if let target: AnyObject = targetView{
if NSStringFromClass(target.classForCoder) == "UILabel"{
if target is UILabel{
fontSize.text = "fontSize:\((target as! UILabel).font.pointSize)"
if let color = (target as! UILabel).textColor{
if let hex = toHexString(color){
fontColor.text = "fontColor:#\(hex)"
}
}
}
}

Expand Down Expand Up @@ -80,14 +88,18 @@ class InfoView: UIView {
fontSize = UILabel(frame: CGRect(x: margin, y: 110.0, width: frame.size.width - 20.0, height: 20.0))
fontSize.text = "fontSize:None"
fontSize.textColor = UIColor.whiteColor()
fontColor = UILabel(frame: CGRect(x: margin, y: 130.0, width: frame.size.width - 20.0, height: 20.0))
fontColor.text = "fontColor:None"
fontColor.textColor = UIColor.whiteColor()
super.init(frame: frame)
self.addSubview(x)
self.addSubview(y)
self.addSubview(width)
self.addSubview(height)
self.addSubview(bkColor)
self.addSubview(fontSize)
self.layer.cornerRadius = 20.0
self.addSubview(fontColor)
self.layer.cornerRadius = 10.0
}

required init?(coder aDecoder: NSCoder) {
Expand Down
58 changes: 38 additions & 20 deletions Source/ViewMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,43 @@ final public class ViewMonitor{
}

private func addExecuteButton(){
if executeButton == nil{
guard let executeButton = executeButton else{
let deviceSize:CGSize = UIScreen.mainScreen().bounds.size
executeButton = MonitorButton(frame: CGRectMake(deviceSize.width - 100.0, 20.0, 72.0, 49.0))
self.executeButton = MonitorButton(frame: CGRectMake(deviceSize.width - 100.0, 20.0, 72.0, 49.0))
let frameworkBundle = NSBundle(forClass: ViewMonitor.self)
if let buttonPath = frameworkBundle.pathForResource("button", ofType: "png"),let buttonImage = UIImage(named: buttonPath){
executeButton?.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
self.executeButton?.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
}else if let buttonImage = UIImage(named: "button"){
executeButton?.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
self.executeButton?.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
}else{
executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.blackColor()), forState: UIControlState.Normal)
self.executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.blackColor()), forState: UIControlState.Normal)
}
if let selectedButtonPath = frameworkBundle.pathForResource("button_selected", ofType: "png"),let buttonSelectedImage = UIImage(named: selectedButtonPath){
executeButton?.setBackgroundImage(buttonSelectedImage, forState: UIControlState.Selected)
self.executeButton?.setBackgroundImage(buttonSelectedImage, forState: UIControlState.Selected)
}else if let buttonSelectedImage = UIImage(named: "button_selected"){
executeButton?.setBackgroundImage(buttonSelectedImage, forState: UIControlState.Selected)
self.executeButton?.setBackgroundImage(buttonSelectedImage, forState: UIControlState.Selected)
}else{
executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.redColor()), forState: UIControlState.Selected)
self.executeButton?.setBackgroundImage(createImageFromUIColor(UIColor.redColor()), forState: UIControlState.Selected)
}
executeButton?.addTarget(self, action: "manualExecute:", forControlEvents: UIControlEvents.TouchUpInside)
self.executeButton?.addTarget(self, action: "manualExecute:", forControlEvents: UIControlEvents.TouchUpInside)

rootView?.addSubview(executeButton!)
rootView?.bringSubviewToFront(executeButton!)
let pan = UIPanGestureRecognizer(target: self, action: "dragEvent:")
self.executeButton?.addGestureRecognizer(pan)
rootView?.addSubview(self.executeButton!)
rootView?.bringSubviewToFront(self.executeButton!)
return
}

rootView?.addSubview(executeButton)
rootView?.bringSubviewToFront(executeButton)
}

@objc private func dragEvent(sender:UIPanGestureRecognizer){
let diff = sender.translationInView(rootView)
let center = CGPointMake(sender.view!.center.x + diff.x, sender.view!.center.y + diff.y)
sender.view?.center = center
sender.setTranslation(CGPointZero, inView: rootView)
}

//execute
@objc func manualExecute(sender:MonitorButton){
sender.selected = !sender.selected
Expand All @@ -137,14 +148,21 @@ final public class ViewMonitor{
//make 100 * 100 information view
// have to set tag to reject.
private func addInfoView(){
let deviceSize:CGSize = UIScreen.mainScreen().bounds.size
infoView = InfoView(frame: CGRect(x: deviceSize.width - 220.0, y: 70.0, width: 200.0, height: 150.0))
let color = UIColor.blackColor()
let alphaColor = color.colorWithAlphaComponent(0.6)
infoView?.backgroundColor = alphaColor
infoView?.hidden = true
rootView?.addSubview(infoView!)
rootView?.bringSubviewToFront(infoView!)
guard let infoView = infoView else{
let deviceSize:CGSize = UIScreen.mainScreen().bounds.size
self.infoView = InfoView(frame: CGRect(x: deviceSize.width - 220.0, y: 70.0, width: 200.0, height: 160.0))
let color = UIColor.blackColor()
let alphaColor = color.colorWithAlphaComponent(0.6)
self.infoView!.backgroundColor = alphaColor
self.infoView!.hidden = true
let pan = UIPanGestureRecognizer(target: self, action: "dragEvent:")
self.infoView!.addGestureRecognizer(pan)
rootView?.addSubview(self.infoView!)
rootView?.bringSubviewToFront(self.infoView!)
return
}
rootView?.addSubview(infoView)
rootView?.bringSubviewToFront(infoView)
}

private func deleteAllMonitorViews(){
Expand Down
2 changes: 1 addition & 1 deletion ViewMonitor.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ViewMonitor"
s.version = "1.0.5"
s.version = "1.0.6"
s.summary = "view detail monitor"
s.description = <<-DESC
You can measure view detail.
Expand Down

0 comments on commit c239c7d

Please sign in to comment.