iPhone Development - Setting UIWebView font

后端 未结 9 2098
别那么骄傲
别那么骄傲 2020-11-28 04:00

I have to show rich text that i pull from server, so i\'m using UIWebView. Now the problem is that i have no control over the font which is used in UIWebView. How can i chan

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 04:46

    Here is my easy to use and easy to expand solution with more font settings:

                    myHTMLLabel = [[UIWebView alloc] initWithFrame:CGRectMake(myX,myY,myWidth,myHeight)];
    
                    myHTMLLabel.userInteractionEnabled=NO;
                    myHTMLLabel.scalesPageToFit=NO;
    
                    [myHTMLLabel setOpaque:NO];
                    myHTMLLabel.backgroundColor = myBackColor;
    
                    NSString *myHTMLText = [NSString stringWithFormat:@""
                                            ""
                                            " [text]"];
    
                    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[text]" withString: myText];
                    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontName]" withString: myFontName];
                    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontSize]" withString: myFontSize];           
                    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontColor]" withString: myFontColorHex];
                    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[textAlign]" withString: myFontAlign];
    
    
                    NSLog(@"*** renderHTMLText --> myHTMLText: %@",myHTMLText);
    
                    [myHTMLLabel loadHTMLString:myHTMLText baseURL:nil];
    

提交回复
热议问题