Friday 15 May 2015

objective c - Trying to set UIControl objects' frames through a function -


I am trying to create a function to resize something like UILBull or UI buttons without typing the three rows I'm out every time this is what I have.

  - (zero) setObject: (UIControl *) Object size width: (NSInteger) Width height: (NSInteger) height {CGRect labelFrame = object.frame; LabelFrame.size = CGSizeMake (width, height); Object.frame = labelFrame; }   

However, when I do a UILabel (UIControl *) object, then this "incompatible indicator type" says how can I fix it for working for anything Which I can put on UIView?

Labels are not a subclass of UIControl You can use UIView instead of UIControl. Here is the hierarchy for UILabel UILabel: UIView: UIResponder: NSObject - (zero) setObject: (UIView *) Object SizeWidth: (NSInteger) Width Height: (NSInteger) Height {CGRect labelFrame = Object.frame; LabelFrame.size = CGSizeMake (width, height); Object.frame = labelFrame; }

There is a suggestion for you, the name of the method sounds strange to me. You can write a simple category to update the size of UIView. You can simply call with the following category

  [myLabel setWidth: 20 and Height: 20];   

On UIView + MyCategory.h

  #import & lt; UIKit / UIKit.h & gt; @ Interface UIView (MyCategory) - (zero) setweath: (NSiEteger) Avid and High: (NSINtegaeer) AHEIT; UiviView + Micration.M  
  #import "UIView + MyCategory.h" @ Permission UIView (MyCategory) - (zero) SetWed: @end   

( NSiEtegaGr) Avidth and Height: (NSINTEGAR) AHEIT; {CGTTF frameOutoUpdate = self.frame; FrameToUpdate.size = CGSizeMake (aWidth, aHeight); Self.frame = frameToUpdate; } @end

No comments:

Post a Comment