Learn more! A collection of iOS trivia

Learn more! A collection of iOS trivia

CAGradientLayer

The CAGradientLayer class is used to draw a color gradient on its background color to fill the entire shape of the layer, including rounded corners. This class inherits from the CALayer class and is very convenient to use.

Similar to the gradient processing in Quartz 2D, a gradient has a starting position (startPoint) and an ending position (endPoint). Between these two positions, we can specify a set of color values ​​(colors, elements are CGColorRef objects), which can be two or more, and each color value corresponds to a location (locations). In addition, gradients are divided into axial gradients and radial gradients.

Let's write an example to see the specific use of CAGradientLayer:

  1. CAGradientLayer *layer = [CAGradientLayer layer];
  2. layer.startPoint = (CGPoint){ 0 .5f, 0 .0f};
  3. layer.endPoint = (CGPoint){ 0 .5f, 1 .0f};
  4. layer.colors = [NSArray arrayWithObjects:(id)[UIColor blueColor].CGColor, (id)[UIColor redColor].CGColor, (id)[UIColor greenColor].CGColor, nil];
  5. layer.locations = @[ @0 .0f, @0 .6f, @1 .0f];
  6. layer.frame = self.view.layer.bounds;
  7. [self.view.layer insertSublayer:layer atIndex: 0 ];

refer to

CAGradientLayer Class Reference

Handling Ineligible Devices in Xcode

I changed to a new computer, installed Xcode 6.3, created a new certificate and profile, opened Xcode, and connected my phone. But then I found that the device was marked as Ineligible Devices and was not recognized. The situation is similar to the following picture:

The computer is trusted, and the certificates and profiles are OK. I tried restarting Xcode and reconnecting the phone several times, but it didn't work. I just can't select the device. *** I selected the device in Product->Destination. But I still can't select it in the toolbar. I'm so frustrated. Please help.

User comment: I changed the iOS SDK to iOS 7 and it was available, but then I ignored it. It was available again in iOS 8 SDK for unknown reasons...

Hide the cursor of UITextField after iOS 7

After the new project only supports iOS 7, many things become much simpler, just like hiding the cursor of UITextField, with a simple sentence:

  1. textFiled.tintColor = [UIColor clearColor];

Usually when we use UIPickerView as our UITextField's inputView, we need to hide the cursor. Of course, if you want to change the cursor color, you can do the same.

There is a legacy problem with this approach: usually when we use UIPickerView as the inputView of UITextField, we don't want to perform various menu operations (select all, copy, paste), but when we just want to set the tintColor of UITextField, we can still perform these operations, so additional processing is required. We can handle this problem like this: in textFieldShouldBeginEditing:, we set the userInteractionEnabled of UITextField to NO, and then in textFieldShouldEndEditing:, set this value back. As follows:

  1. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  2. textField.userInteractionEnabled = NO;
  3. return YES;
  4. }
  5. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  6. textField.userInteractionEnabled = YES;
  7. return YES;
  8. }

That's it. Of course, this is just one way we are currently using. There are other methods, just google or stackoverflow.

Left alignment issue of Chinese text in UIAlertView after iOS 7

Before iOS 7, if we want to display the text in UIAlertView on the left, we can use the following code to handle it:

  1. for (UIView *view in alert.subviews) {
  2. if ([[view class ] isSubclassOfClass:[UILabel class ]]) {
  3. ((UILabel*)view).textAlignment = NSTextAlignmentLeft;
  4. }
  5. }

But unfortunately, after iOS 7, Apple doesn't allow us to do this. When we get the subviews of UIAlertView, we get an empty array and we can't get the label we want. What should we do? Three ways: tell the product manager and UED that this can't be implemented (of course, this will be despised, and people will say you are incompetent); write it yourself; find a third-party open source code. Hehe, but because of the tight schedule recently, I decided to tell them that it can't be implemented, haha. But I found an open source on github, Custom iOS AlertView, with a lot of stars. It looks good, I will study it carefully later.

<<:  5 Do's and 3 Don'ts in Code Comments

>>:  Why did Google and Apple develop their own programming languages?

Recommend

“Soul” product operation analysis!

Social needs are the third need based on physiolo...

Short videos + full links, a new way of marketing movies in 2020

2020 was a turbulent year for the film industry. ...

Emei School Guo Xiang anchor online training course, valued at 299 yuan

The course comes from the online training course ...

Analysis of Himalaya audio content operations!

The author has conducted an in-depth analysis of ...

Where can Ningbo students drink and taste tea? I'll tell you

Recommended places for drinking tea and spa in Ni...

Tech Neo Technology Salon 15th Special Report - How CDN Makes the Network Smarter

【51CTO.com original article】 [51CTO original arti...

A complete and effective event planning plan!

Event planning refers to the planning of differen...

How to use deep learning AI to detect and prevent malware and APT

[[163896]] [51CTO.com Quick Translation] Deep Ins...

After the bonus period, you should take this complete guide to channel operation

The traffic dividend has passed, so how will traf...

How to make users fall in love with watching ads?

No one likes to watch ads, but everyone needs to ...