Compatibility of ios5 and ios6 - ios

I have a problem regarding incompatibility of ios5 vs ios6
While I was working on my project with ios5
label.textAlignment = UITextAlignmentCenter;
then updated to ios6
label.textAlignment = NSLineBreakByTruncatingTail;
Once I run my code on the device which ios5 installed, that give me error.
I am about to upload my app to appstore, however I want my app also supports ios5 as well. How I am going to handle both ios5 and ios6!
Thanks in advance!

The acceptable values for NSTextAlignment are:
NSTextAlignmentLeft
NSTextAlignmentCenter
NSTextAlignmentRight
NSTextAlignmentJustified
NSTextAlignmentNatural
Of those any of the first three will work equally under iOS 5 and 6.
NSLineBreakByTruncatingTail isn't really a valid type of text alignment though it'll look like NSTextAlignmentNatural at runtime because of the way the C enums line up.
So you'll need either to switch to NSTextAlignmentLeft across the board or to do a functionality check. Thankfully the change in text alignment type is in support of the new ability to push attributed strings to UILabel (and elsewhere) so that gives you something to hang off.
E.g.
if([label respondsToSelector:#selector(attributedText)])
label.textAlignment = NSTextAlignmentNatural;
else
label.textAlignment = NSTextAlignmentLeft;
Though the else is technically redundant because NSTextAlignmentLeft is the default value.

Related

iOS 14 Crash when setting label line break mode, text alignment and text color

I've been using React Native SVG for a project and with the upgrade to iOS 14 I've started to receive a crash on a resizable box. I've tracked the crash down to three assignments in a library but am unsure of why they cause a EXEC_BAD_INSTRUCTION or a EXC_BAD_ACCESS.
This crash occurs only after the initial render within the app when you resize the box. The first render is fine and then the subsequent move of the item causes the fault. This code worked in iOS 13 but does not in iOS 14.
I've created a reproducible example here. I've also created an issue on the repo here.
In the library I've attempted to hard code the assignments to known good values assuming something went wrong with how they were being assigned with no luck.
The following is where I receive the error:
label.attributedText = (__bridge NSAttributedString * _Nullable)(attrString);
label.baselineAdjustment = UIBaselineAdjustmentNone;
//label.lineBreakMode = NSLineBreakByWordWrapping;
label.backgroundColor = UIColor.clearColor;
//label.textAlignment = NSTextAlignmentRight;
label.numberOfLines = 0;
label.opaque = NO;
label.font = font;
//label.textColor = [UIColor colorWithCGColor:color];
This is from line 203 in RNSVGTSpan, the comments are the lines I've removed to make it work but this takes away functionality that is used.
I'm at a loss as to why this would work on the initial render but not with the subsequent changes in iOS 14 but works flawlessly in iOS 13.

Multiline label in iOS8

I have updated my device iOS to iOS 8 and now multiline label is not working. Its displaying very weird screen shot attached.
So please can you suggest me the solution.
I already set Number of lines =0 and it was working perfect in ios 7.
Not using Autolayout and story board.
This code help you.It works fine me.Edit your code according to need
UILabel *problem = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 200, 100)];
problem.lineBreakMode=NSLineBreakByWordWrapping;
problem.text=#"Please use this code it may help you it works fine for me";
problem.numberOfLines=0;
[self.view addSubview:problem];
Strangely enough, this fix doesn't work if you don't use all of it:
Set the line break mode to word wrapping (if that's the affect you want).
Set the number of lines to 0 (I had it set to 2 and it still didn't work).
Not sure if something changed here with the introduction with iOS 8 but my previous code (just setting the number of lines to 2) was working great on iOS 7.
Anyone else face a similar issue?
Do you use a custom font?Try changing the font.

Use iOS 6 Style Segmented Control in iOS 7?

Is it possible to have a segmented control on an iOS 7 device show up as the iOS 6 version of the control?
We really aren't ready for an interface redesign and the new flat control doesn't jive with the rest of our UI. It would definitely be best to keep the iOS 6 style for now, if possible.
To clarify, I am compiling using the iOS 6.1 Base SDK. I am aware that this is the "obvious" answer to my question, but it does not work. Most other UI elements will show up with iOS 6 styling by doing this, but like the UIAlertView and UIActionSheet, the UISegmentedControl does not. However, unlike the UIAlertView and UIActionSheet, UISegmentedControls do not feel like a "system" item; they should be able to display in iOS 6 mode.
Edit: I thought it would be helpful if I finally included a picture with this (probably should have done this from the start). However, the answer I provided did fix the issue. Also, in retrospect, it looks like this might be the iOS 6 style after all, it's just displaying so wrong that it appears like iOS 7 style.
I manage to do a pretty good job of solving this problem by setting all the attributes manually, but it is not quite perfect.
This is what I ended up doing:
- (void)fixSegmentedControlForiOS7
{
NSInteger deviceVersion = [[UIDevice currentDevice] systemVersion].integerValue;
if(deviceVersion < 7) // If this is not an iOS 7 device, we do not need to perform these customizations.
return;
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
nil];
[self.segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[self.segmentedControl setTitleTextAttributes:highlightedAttributes forState:UIControlStateHighlighted];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
self.segmentedControl.tintColor = [UIColor colorWithRed:49.0 / 256.0 green:148.0 / 256.0 blue:208.0 / 256.0 alpha:1];
}
To fix images assigned with InterfaceBuilder use this code:
- (void)fixImagesOfSegmentedControlForiOS7
{
NSInteger deviceVersion = [[UIDevice currentDevice] systemVersion].integerValue;
if(deviceVersion < 7) // If this is not an iOS 7 device, we do not need to perform these customizations.
return;
for(int i=0;i<toSegmentedControl.numberOfSegments;i++)
{
UIImage* img = [toSegmentedControl imageForSegmentAtIndex:i];
UIImage* goodImg = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// clone image with different rendering mode
[toSegmentedControl setImage:goodImg forSegmentAtIndex:i];
}
}
I just ran into this problem today myself. The app I'm working on updating is quite old, and still uses xib files, so I do not know if this works on storyboards or not. As others suggested above, you still need to use the iOS 6.1 SDK, but this alone is not enough. After performing the following steps, I was able to get the old UISegmentedControl appearance back:
Open the interface builder document in question
Go to the file inspector (first inspector tab; has a document icon)
Under the "Interface Builder Document" section, change "Opens in" to Xcode 4.6
I do believe this is a bug, and I would not be surprised if there isn't a workaround for UISegmentedControl instances created in code. I'm guessing this is somewhat related to the deprecation of the segmentedControlStyle property in iOS 7 (see https://developer.apple.com/library/ios/documentation/uikit/reference/UISegmentedControl_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/UISegmentedControl/segmentedControlStyle).
Hope this helps someone out there.
If you save the iPhoneOS6.1.sdk file from the previous version of XCode and add it to Xcode 5 in the same path you can then build an app against the 6.1 SDK so that when it runs on 7 everything is like 6. Linking against iOS7 SDK tells iOS to make everything look like iOS7 if possible. Essentially then you have an iOS6 app but building it with XCode 5.
If you use images on any of your UISegmentedControl segments, you'll need to add some code to set those properly on iOS 7, otherwise they'll be used as a template image and the selected segment will be a cutout of the segment's background.
UISegmentedControl under iOS 7 interprets its images as being in rendering mode UIImageRenderingModeAlwaysTemplate unless otherwise specified. I had to use -[UIImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] on each segment's image for iOS 7 to achieve the previous behavior.
Either you could:
Not update your app at all for iOS7 until you're ready to make some UI changes. Apps compiled against the iOS6 SDK will run in iOS6 Compatibility mode on iOS7 and will look exactly the same as they did in iOS6.
Apply custom background, separator, etc images to your segmented controls that mimic the look they had in iOS6.
Yes, it is possible if you recreate the control by your own. Create a fake segmented control that looks like and work like one.
In my app, I have set the Segmented control to "Bar" style. It renders in ios6 style on my ios7 iphone5 (whoa, 5,6,7). However, the text inside the segments are cut and have the three dots "..." added, no matter how wide the view is.
So the ios6 segmented control rendering in ios7 seems really buggy
Is it possible? Not really...
You could make your own custom segmented control.
Or you could use the UIAppearance proxy to customise your segmented control with images but then it's your responsibility to make it look like it was on iOS 6.

TTTAttributedLabel linebreakmode broken in iOS6

If I set linebreakmode to truncation tail in the TTTAttributedLabel Example App "Espresso" everything looks like it should be in iOS 5 Simulator but if I run the App in iOS 6 Simulator the text gets truncated after the first line although the text goes over 3 lines. Number of lines are set to zero. Did I miss something? After I noticed this behavior in the Espresso App I can stop worrying about the brokeness of the code in my own app.
Any suggestions? Thanks!
I currently faced the same problem. Try setting the LineBreakMode before you actually set your text. E.g.:
TTTAttributedLabel* descriptionLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(20, 120, 280, expectedSize.height)];
descriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
descriptionLabel.numberOfLines = 0;
descriptionLabel.text = description;
Labels and textviews in iOS 6 support attributed text natively. So if you don't need to support older versions of iOS, you can get rid of 3rd party control.
In my case, for some reason following code was causing the label to show only one row. Removing it helped
' self.attributedLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;'
Strangely the problem solved itself. I could not figure out why this particular problem happened on iOS6 Simulator but now it works with NSLineBreakTailTruncation on iOS6 Device and Simulator.
Thank you for your responses!
You can have a try.
NSMutableAttributedString * mutableAttributedString = [[NSMutableAttributedString alloc]initWithString:text];
[self.attributedLabel setText:mutableAttributedString afterInheritingLabelAttributesAndConfiguringWithBlock:nil];

custom UIFont issue in XCode

I am working with custom fonts and I have applied a custom font called "CicleSemi", I have added this font in info.plist file and below is the code which I have written
DateLabel.font = [UIFont fontWithName:#"CicleSemi" size:15.0];
This works fine, for english language in my app, but for russian language , I know that this font is not available , so Xcode automatically shifts to system font and its shifting also but the issue is that the font is becoming "BOLD" but I want it normal, and I dont have any clue what might be the issue, how xcode is treating this.
So friends, if you have any clue or suggestions please let me know.
Regards
Ranjit

Resources