Basic knowledge of IOS development-fragment 12, basic knowledge of ios-Fragment

Source: Internet
Author: User

Basic knowledge of IOS development-fragment 12, basic knowledge of ios-Fragment

1: Use Delegate

. H # import <UIKit/UIKit. h> @ protocol FilterHeaderViewDelegate <NSObject> @ required-(void) handle :( id) sender; @ endextern float handle; @ interface FilterHeaderView: UICollectionReusableView @ property (nonatomic, weak) id <FilterHeaderViewDelegate> delegate; @ end. m-(void) moreBtnClicked :( id) sender {if ([self. delegate respondsToSelector: @ selector (filterHeaderViewMoreBtnClicked :)]) {[self. delegate filterHeaderViewMoreBtnClicked: self. moreButton];} note that in. m will call the above method: [self. moreButton addTarget: self action: @ selector (moreBtnClicked :) forControlEvents: UIControlEventTouchUpInside]; when calling this plug-in, remember to assign delegate to self and introduce FilterHeaderViewDelegate to <>; then you can implement the deletage method;

2: Implement UIButton display in different States

[Btn setTitle: @ "more" forState: UIControlStateNormal]; [btn setTitle: @ "collapse" forState: UIControlStateSelected]; btn. titleLabel. font = [UIFont systemFontOfSize: 12]; [btn setTitleColor: [UIColor blackColor] forState: UIControlStateNormal]; [btn setTitleColor: [UIColor blackColor] forState: UIControlStateSelected]; btn. response = NO; [btn setImage: [UIImage imageNamed: @ "response"] forState: UIControlStateNormal]; [btn setImage: [UIImage imageNamed: @ "response"] forState: UIControlStateSelected]; btn. titleEdgeInsets = UIEdgeInsetsMake (0,-btn. imageView. frame. size. width-kImageToTextMargin, 0, btn. imageView. frame. size. width); btn. imageEdgeInsets = UIEdgeInsetsMake (0, btn. titleLabel. frame. size. width, 0,-btn. titleLabel. frame. size. width );

3: Adding click events in the uiview

If (! _ TicketView) {_ TicketView = [UIView new]; _ TicketView. backgroundColor = [UIColor whiteColor]; // added the click event handler * tapGesture = [[delealloc] initWithTarget: self action: @ selector (TickAction :)]; [_ TicketView addGestureRecognizer: tapGesture]; [_ BelowView addSubview: _ TicketView];} call:-(void) TickAction :( id) sender {NSLog (@ "sdfsdfsdf ");}

4: The Rolling view UIScrollView is incompatible in ios7 and cannot be rolled.

Put the contentSize definition in viewDidLayoutSubviews;-(void) viewDidLayoutSubviews {_ myScrollView. contentSize = CGSizeMake (SCREEN_WIDTH, 600 );}

5. Flip the icon on UIButton.

# Define DEGREES_TO_RADIANS (angle)/180.0 * M_PI) Call: _ BtnMoreContent. imageView. transform = convert (_ BtnMoreContent. imageView. transform, DEGREES_TO_RADIANS (180 ));

6. Create a background image and dynamically load it from the network.

Call in viewDidLoad:-(void) LoadBackViewImage {UIImageView * bgView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; bgView. image = [UIImage imageNamed: @ "bgWeatherEmpty"]; [bgView sd_setImageWithURL: [NSURL URLWithString: self. backImageUrl] placeholderImage: [UIImage imageNamed: @ "bgWeatherEmpty"] completed: ^ (UIImage * image, NSError * error, SDImageCacheType cacheType, NSURL * im AgeURL) {dispatch_async (dispatch_get_main_queue (), ^ {bgView. image = image; [self. view addSubview: bgView]; [self. view sendSubviewToBack: bgView];});}];} Note: UIView level management (sendSubviewToBack, bringSubviewToFront) displays a UIView at the beginning. You only need to call the bringSubviewToFront () of its parent view () method. To push a UIView layer to the backend, you only need to call the sendSubviewToBack () method of its parent view.

7. Load xib to other views.

Create a UIView xib file. You can read any article on the Internet to specify the custom Class in the property to the created file. h file ;. h # import <UIKit/UIKit. h> @ interface LKTextView: UIView @ property (strong, nonatomic) IBOutlet UILabel * lbText;-(IBAction) bt_pressed :( id) sender; @ property (strong, nonatomic) IBOutlet UITextField * textView; + (LKTextView *) instanceTextView; @ end. m # import "LKTextView. h "# import" RKTabView. h "# import" RKTabItem. h "@ implementation LKTextView @ synthesize textView; @ synthesize lbText; + (LKTextView *) Comment {NSArray * nibView = [[NSBundle mainBundle] Comment: @" LKTextView "owner: nil options: nil]; return [nibView objectAtIndex: 0];}-(id) initWithCoder :( NSCoder *) aDecoder {self = [super initWithCoder: aDecoder]; if (self) {// other [self initViews];} return self;}/*** @ author wujunyang, 15-04-30 16:04:03 ** @ brief this section uses RKTABVIEW to create a tag */-(void) initViews {UIView * vi = [[UIView alloc] initWithFrame: CGRectMake (0, 0, 20, 30)]; vi. backgroundColor = [UIColor redColor]; [self addSubview: vi]; RKTabView * titledTabsView = [[RKTabView alloc] initWithFrame: CGRectMake (0, 0,200, 50)]; [self addSubview: titledTabsView]; RKTabItem * mastercardTabItem = [RKTabItem createUsualItemWithImageEnabled: nil imageDisabled: [UIImage imageNamed: @ "mastercard"]; mastercardTabItem. titleString = @ "MasterCard"; RKTabItem * paypalTabItem = [RKTabItem createUsualItemWithImageEnabled: nil imageDisabled: [UIImage imageNamed: @ "paypal"]; paypalTabItem. titleString = @ "PayPal"; RKTabItem * visaTabItem = [RKTabItem createUsualItemWithImageEnabled: nil imageDisabled: [UIImage imageNamed: @ "visa"]; visaTabItem. titleString = @ "Visa"; RKTabItem * wuTabItem = [RKTabItem createUsualItemWithImageEnabled: nil imageDisabled: [UIImage imageNamed: @ "wu"]; wuTabItem. titleString = @ "Western Union"; RKTabItem * wireTabItem = [RKTabItem createUsualItemWithImageEnabled: nil imageDisabled: [UIImage imageNamed: @ "wire-transfer"]; wireTabItem. titleString = @ "Wire Transfer"; // mastercardTabItem. tabState = TabStateEnabled; titledTabsView. darkensBackgroundForEnabledTabs = YES; titledTabsView. horizontalInsets = HorizontalEdgeInsetsMake (25, 25); titledTabsView. titlesFontColor = [UIColor colorWithWhite: 0.9f alpha: 0.8f]; titledTabsView. tabItems = @ [mastercardTabItem, paypalTabItem, visaTabItem, wuTabItem, wireTabItem];}/* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. -(void) drawRect :( CGRect) rect {// Drawing code} */-(IBAction) bt_pressed :( id) sender {lbText. text = textView. text;} @ end and then call the view. m:-(void) viewDidLoad {LKTextView * text = [LKTextView instanceTextView]; text. frame = CGRectMake (100,100, text. frame. size. width, text. frame. size. height); text. textView. text = @ "input"; [self. view addSubview: text]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .}

8: good plug-ins

Extended FDTemplateLayoutCell extension that automatically calculates the UITableViewCell height under AutoLayout: https://github.com/RafaelKayumov/RKTabView for labels without error

9: ios7 and ios8 about the navigation bar

In versions earlier than iOS 7, the view in UIViewController is automatically adjusted to remove the height of the navigation bar, and the control is automatically placed below the navigation bar. In iOS7, The wantsFullScreenLayout attribute of UIViewController is discarded. After all uiviewcontrollers are created, full Screen is used by default. Therefore, if some controls on the application interface with the navigation bar are overwritten by the navigation bar. Solution: You can use the extenendlayoutincludesopaquebars and edgesForExtendedLayout attributes added by ios7 UIViewController. This attribute specifies whether to extend to the bar area when bar uses an opaque image. The default value is NO. In edgesForExtendedLayout, this attribute specifies whether the view is extended to the Bar region when the Bar uses an opaque image. The default value is NO. EdgesForExtendedLayout indicates whether the view covers the surrounding area. The default value is UIRectEdgeAll, that is, the top, bottom, and left are overwritten. In this way, the top is not extended to the area covered by the navigation bar, we can remove the extension of the top area. The implementation code is as follows: self. extendedLayoutIncludesOpaqueBars = NO; self. edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;

 11: differences between initWithNibName/awakeFromNib/initWithCoder

First, the initWithNibName method is created in the controller class in IB, but it is used when the controller is instantiated through Xcode. 2. initWithCoder is called when a class is created in IB but instantiated in xocde. for example, if you create a controller nib file through IB and then instantiate the controller through initWithNibName in xcode, the controller's initWithCoder will be called. or a view nib file. Call initWithCoder when creating a view using a similar method. 3. awakeFromNib when. when the nib file is loaded, an awakeFromNib message is sent. every object in the nib file, each object can define its own awakeFromNib function to respond to this message and perform some necessary operations. That is to say, awakeFromNib is executed when a view object is created through the nib file. 4. Differences and connections between initWithNibName and loadNibNamed: Differences and connections between initWithNibName and loadNibNamed. I think I am a little confused about the two. What is it like? In fact, the difference between them will not be so confused. Because these two methods are not the same. Since the two methods need to be described, the difference should be emphasized. But in the first step, we still need to peat them. Their contact: You can use this method to load the user interface (xib file) to our code. In this way, you can operate on the content of the xib file by operating on the loaded (xib) object. Next we will go to the topic to discuss the differences: 1. showViewController's initWithNibName method ShowViewController * showMessage = [[ShowViewController alloc] initWithNibName: @ "ShowViewController" bundle: nil]; self. showViewController = showMessage; [showMessage release]; 2. videoCellController's loadNibNamed method NSArray * nib = [[NSBundle mainBundle] loadNibNamed: @ "Save3ViewController" owner: self options: nil]; self. showViewController = [nib las TObject]; [nib objectAtIndex: 0]; conclusion: it may be the same if they are initialized. However, when we opened the relationship between the xib instances, we suddenly realized that their integration classes were different. 1. the class of the initWithNibName xib to be loaded is the View Controller class we have defined. the loading method is different. The initWithNibName method is delayed loading. The control on this View is nil. It is not the nil loadNibNamed method until it is displayed, each element in the xib object loaded with this method already exists. (Understand the rule carefully: when using loadNibNamed: owner: options:, the File's Owner shocould be NSObject, the main view shocould be your class type, and all outlets shocould be hooked up to the view, not the File's Owner .) fifth, the difference between initWithCoder and initWithFrame nitWithoder is called when loading objects from the nib file. For example, if your view is from nib, the view function is called. (Called by the Framework) initWithFrame (called by the user to initialize the object)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.