3

Since iOS 7 , Arabic fonts are now supported, but when i use the:

   lbl.font=[UIFont fontWithName:@"Scheherazade" size:33];

The text reaches the edges of the UILabel and some of the words cannot be read !!

How to fix this problem?? here is describing my problem.A Picture

here is my code:

lbl  = [[UILabel alloc]initWithFrame:CGRectMake(20, 50, 280, 320)];
lbl.text = @"شِّرِ ٱلَّذِينَ ءَامَنُوا۟ وَعَمِلُوا۟ ٱلصَّٰلِحَٰتِ أَنَّ لَهُمْ جَنَّٰتٍۢ تَجْرِى مِن تَحْتِهَا ٱلْأَنْهَٰرُ ۖ كُلَّمَا رُزِقُوا۟ مِنْهَا مِن ثَمَرَةٍۢ رِّزْقًۭا ۙ قَالُوا۟ هَٰذَا ٱلَّذِى رُزِقْنَا مِن قَبْلُ ۖ وَأُتُوا۟ بِهِۦ مُتَشَٰبِهًۭا ۖ وَلَهُمْ فِيهَآ أَزْوَٰجٌۭ مُّطَهَّرَةٌۭ ۖ وَهُمْ فِيهَا خَٰلِدُونَ";
lbl.font=[UIFont fontWithName:@"Scheherazade" size:33.0];
lbl.backgroundColor = [UIColor whiteColor];
lbl.lineBreakMode = NSLineBreakByCharWrapping;
[self.view addSubview:lbl];
lbl.numberOfLines = 0;
lbl.textAlignment = NSTextAlignmentCenter;
Mutawe
  • 6,464
  • 3
  • 47
  • 90

5 Answers5

0

I am seeing the same issue in iOS 7. I think there is a bug where NSLineBreakByCharWrapping is always treated as NSLineBreakByWordWrapping. I have submitted to Apple.

tbraun89
  • 2,246
  • 3
  • 25
  • 44
0

I was having a similar problem where my custom font was cut off on the bottom (especially in iOS 7), and I found a few answers on this post to be quite helpful where I edited the font file directly and changed the ascender and/or descender attributes.

Custom installed font not displayed correctly in UILabel

In your case there might be other attributes in that font file that you can edit to prevent it from being cut off on the left and ride sides.

Community
  • 1
  • 1
teradyl
  • 2,584
  • 1
  • 25
  • 34
0

Try setting UILabel's preferredMaxLayoutWidth to the width of its superview (optionally with a left/right padding).

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
0

I just changed the line break mode "NSLineBreakByWordWrapping". I think it issue occurs due to arabic text.

UILabel * lbl = [[UILabel alloc]initWithFrame:CGRectMake(20, 50, 280, 320)];

lbl.text = @"شِّرِ ٱلَّذِينَ ءَامَنُوا۟ وَعَمِلُوا۟ ٱلصَّٰلِحَٰتِ أَنَّ لَهُمْ جَنَّٰتٍۢ تَجْرِى مِن تَحْتِهَا ٱلْأَنْهَٰرُ ۖ كُلَّمَا رُزِقُوا۟ مِنْهَا مِن ثَمَرَةٍۢ رِّزْقًۭا ۙ قَالُوا۟ هَٰذَا ٱلَّذِى رُزِقْنَا مِن قَبْلُ ۖ وَأُتُوا۟ بِهِۦ مُتَشَٰبِهًۭا ۖ وَلَهُمْ فِيهَآ أَزْوَٰجٌۭ مُّطَهَّرَةٌۭ ۖ وَهُمْ فِيهَا خَٰلِدُونَ";
lbl.font=[UIFont fontWithName:@"Scheherazade" size:33.0];
lbl.backgroundColor = [UIColor white];
lbl.lineBreakMode = NSLineBreakByWordWrapping;
[self.view addSubview:lbl];
lbl.numberOfLines = 0;
lbl.textAlignment = NSTextAlignmentCenter;
Saad Ur Rehman
  • 798
  • 1
  • 10
  • 19
-2

Find your problem actually font size was not channing with your lbl.font=[UIFont fontWithName:@"Scheherazade" size:33.0]; try to adjust your font size with this code

lbl.font= [UIFont systemFontOfSize:10];

I have updated my code and now i am able to see complete text

UILabel *lbl  = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 280, 320)];
lbl.text = @"شِّرِ ٱلَّذِينَ ءَامَنُوا۟ وَعَمِلُوا۟ ٱلصَّٰلِحَٰتِ أَنَّ لَهُمْ جَنَّٰتٍۢ تَجْرِى مِن تَحْتِهَا ٱلْأَنْهَٰرُ ۖ كُلَّمَا رُزِقُوا۟ مِنْهَا مِن ثَمَرَةٍۢ رِّزْقًۭا ۙ قَالُوا۟ هَٰذَا ٱلَّذِى رُزِقْنَا مِن قَبْلُ ۖ وَأُتُوا۟ بِهِۦ مُتَشَٰبِهًۭا ۖ وَلَهُمْ فِيهَآ أَزْوَٰجٌۭ مُّطَهَّرَةٌۭ ۖ وَهُمْ فِيهَا خَٰلِدُونَ";
lbl.font=[UIFont fontWithName:@"Scheherazade" size:33.0];
lbl.backgroundColor = [UIColor whiteColor];
//lbl.lineBreakMode = NSLineBreakByCharWrapping;
[self.view addSubview:lbl];
lbl.numberOfLines = 0;
lbl.textAlignment = NSTextAlignmentCenter;

screentshot

Hemant Singh Rathore
  • 2,153
  • 1
  • 24
  • 38