Strange Alignment in UITextView










0















Trying to create a new UITextView in a new project and set the alignment to center through storyboard it appears to has a bug.



First image I write three lines:



Second image I start a new paragraph and the cursor goes to left, why?



enter image description hereenter image description here










share|improve this question






















  • what is the textview alignemnt set to ?

    – Teja Nandamuri
    Feb 11 '16 at 17:05











  • what are you trying to do ?

    – Teja Nandamuri
    Feb 11 '16 at 17:06











  • already u asked the same question in yester day also , still now you are not get the answer

    – Anbu.Karthik
    Feb 11 '16 at 17:06











  • Trying to set Text Alignment to center @Mr.T

    – user4385051
    Feb 11 '16 at 17:10












  • where did u set it ? in storyboard ?

    – Teja Nandamuri
    Feb 11 '16 at 17:11















0















Trying to create a new UITextView in a new project and set the alignment to center through storyboard it appears to has a bug.



First image I write three lines:



Second image I start a new paragraph and the cursor goes to left, why?



enter image description hereenter image description here










share|improve this question






















  • what is the textview alignemnt set to ?

    – Teja Nandamuri
    Feb 11 '16 at 17:05











  • what are you trying to do ?

    – Teja Nandamuri
    Feb 11 '16 at 17:06











  • already u asked the same question in yester day also , still now you are not get the answer

    – Anbu.Karthik
    Feb 11 '16 at 17:06











  • Trying to set Text Alignment to center @Mr.T

    – user4385051
    Feb 11 '16 at 17:10












  • where did u set it ? in storyboard ?

    – Teja Nandamuri
    Feb 11 '16 at 17:11













0












0








0








Trying to create a new UITextView in a new project and set the alignment to center through storyboard it appears to has a bug.



First image I write three lines:



Second image I start a new paragraph and the cursor goes to left, why?



enter image description hereenter image description here










share|improve this question














Trying to create a new UITextView in a new project and set the alignment to center through storyboard it appears to has a bug.



First image I write three lines:



Second image I start a new paragraph and the cursor goes to left, why?



enter image description hereenter image description here







ios swift storyboard






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 11 '16 at 17:01







user4385051



















  • what is the textview alignemnt set to ?

    – Teja Nandamuri
    Feb 11 '16 at 17:05











  • what are you trying to do ?

    – Teja Nandamuri
    Feb 11 '16 at 17:06











  • already u asked the same question in yester day also , still now you are not get the answer

    – Anbu.Karthik
    Feb 11 '16 at 17:06











  • Trying to set Text Alignment to center @Mr.T

    – user4385051
    Feb 11 '16 at 17:10












  • where did u set it ? in storyboard ?

    – Teja Nandamuri
    Feb 11 '16 at 17:11

















  • what is the textview alignemnt set to ?

    – Teja Nandamuri
    Feb 11 '16 at 17:05











  • what are you trying to do ?

    – Teja Nandamuri
    Feb 11 '16 at 17:06











  • already u asked the same question in yester day also , still now you are not get the answer

    – Anbu.Karthik
    Feb 11 '16 at 17:06











  • Trying to set Text Alignment to center @Mr.T

    – user4385051
    Feb 11 '16 at 17:10












  • where did u set it ? in storyboard ?

    – Teja Nandamuri
    Feb 11 '16 at 17:11
















what is the textview alignemnt set to ?

– Teja Nandamuri
Feb 11 '16 at 17:05





what is the textview alignemnt set to ?

– Teja Nandamuri
Feb 11 '16 at 17:05













what are you trying to do ?

– Teja Nandamuri
Feb 11 '16 at 17:06





what are you trying to do ?

– Teja Nandamuri
Feb 11 '16 at 17:06













already u asked the same question in yester day also , still now you are not get the answer

– Anbu.Karthik
Feb 11 '16 at 17:06





already u asked the same question in yester day also , still now you are not get the answer

– Anbu.Karthik
Feb 11 '16 at 17:06













Trying to set Text Alignment to center @Mr.T

– user4385051
Feb 11 '16 at 17:10






Trying to set Text Alignment to center @Mr.T

– user4385051
Feb 11 '16 at 17:10














where did u set it ? in storyboard ?

– Teja Nandamuri
Feb 11 '16 at 17:11





where did u set it ? in storyboard ?

– Teja Nandamuri
Feb 11 '16 at 17:11












1 Answer
1






active

oldest

votes


















0














It is because, when you go back and go to new line, you breaking the text alignment. By default the text alignment is set to left.



To change this behaviour: set the text alignment to center, in the following delegate method , so that text always be in center mode, even when the text alignment mode is changed accidentally elsewhere in your code.



#pragma text view delegate method
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
textView.textAlignment=NSTextAlignmentCenter;
return YES;






share|improve this answer























  • I've already tried your fix. But when you start a new paragraph the cursor still on the left until the user write some text

    – user4385051
    Feb 11 '16 at 18:06











  • Yes. I agree. It is because at the point we set the text alignment to center, the previous text alignment is already broken, the new text alignment will be set after we type something. I will see if there is any way to set the textview attributes after we press the return key.

    – Teja Nandamuri
    Feb 11 '16 at 18:08











  • in the meantime I select your answer as right. vote up if you find something to check the textview attributes after return key

    – user4385051
    Feb 12 '16 at 16:19










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35345523%2fstrange-alignment-in-uitextview%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














It is because, when you go back and go to new line, you breaking the text alignment. By default the text alignment is set to left.



To change this behaviour: set the text alignment to center, in the following delegate method , so that text always be in center mode, even when the text alignment mode is changed accidentally elsewhere in your code.



#pragma text view delegate method
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
textView.textAlignment=NSTextAlignmentCenter;
return YES;






share|improve this answer























  • I've already tried your fix. But when you start a new paragraph the cursor still on the left until the user write some text

    – user4385051
    Feb 11 '16 at 18:06











  • Yes. I agree. It is because at the point we set the text alignment to center, the previous text alignment is already broken, the new text alignment will be set after we type something. I will see if there is any way to set the textview attributes after we press the return key.

    – Teja Nandamuri
    Feb 11 '16 at 18:08











  • in the meantime I select your answer as right. vote up if you find something to check the textview attributes after return key

    – user4385051
    Feb 12 '16 at 16:19















0














It is because, when you go back and go to new line, you breaking the text alignment. By default the text alignment is set to left.



To change this behaviour: set the text alignment to center, in the following delegate method , so that text always be in center mode, even when the text alignment mode is changed accidentally elsewhere in your code.



#pragma text view delegate method
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
textView.textAlignment=NSTextAlignmentCenter;
return YES;






share|improve this answer























  • I've already tried your fix. But when you start a new paragraph the cursor still on the left until the user write some text

    – user4385051
    Feb 11 '16 at 18:06











  • Yes. I agree. It is because at the point we set the text alignment to center, the previous text alignment is already broken, the new text alignment will be set after we type something. I will see if there is any way to set the textview attributes after we press the return key.

    – Teja Nandamuri
    Feb 11 '16 at 18:08











  • in the meantime I select your answer as right. vote up if you find something to check the textview attributes after return key

    – user4385051
    Feb 12 '16 at 16:19













0












0








0







It is because, when you go back and go to new line, you breaking the text alignment. By default the text alignment is set to left.



To change this behaviour: set the text alignment to center, in the following delegate method , so that text always be in center mode, even when the text alignment mode is changed accidentally elsewhere in your code.



#pragma text view delegate method
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
textView.textAlignment=NSTextAlignmentCenter;
return YES;






share|improve this answer













It is because, when you go back and go to new line, you breaking the text alignment. By default the text alignment is set to left.



To change this behaviour: set the text alignment to center, in the following delegate method , so that text always be in center mode, even when the text alignment mode is changed accidentally elsewhere in your code.



#pragma text view delegate method
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
textView.textAlignment=NSTextAlignmentCenter;
return YES;







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 11 '16 at 17:28









Teja NandamuriTeja Nandamuri

8,55954079




8,55954079












  • I've already tried your fix. But when you start a new paragraph the cursor still on the left until the user write some text

    – user4385051
    Feb 11 '16 at 18:06











  • Yes. I agree. It is because at the point we set the text alignment to center, the previous text alignment is already broken, the new text alignment will be set after we type something. I will see if there is any way to set the textview attributes after we press the return key.

    – Teja Nandamuri
    Feb 11 '16 at 18:08











  • in the meantime I select your answer as right. vote up if you find something to check the textview attributes after return key

    – user4385051
    Feb 12 '16 at 16:19

















  • I've already tried your fix. But when you start a new paragraph the cursor still on the left until the user write some text

    – user4385051
    Feb 11 '16 at 18:06











  • Yes. I agree. It is because at the point we set the text alignment to center, the previous text alignment is already broken, the new text alignment will be set after we type something. I will see if there is any way to set the textview attributes after we press the return key.

    – Teja Nandamuri
    Feb 11 '16 at 18:08











  • in the meantime I select your answer as right. vote up if you find something to check the textview attributes after return key

    – user4385051
    Feb 12 '16 at 16:19
















I've already tried your fix. But when you start a new paragraph the cursor still on the left until the user write some text

– user4385051
Feb 11 '16 at 18:06





I've already tried your fix. But when you start a new paragraph the cursor still on the left until the user write some text

– user4385051
Feb 11 '16 at 18:06













Yes. I agree. It is because at the point we set the text alignment to center, the previous text alignment is already broken, the new text alignment will be set after we type something. I will see if there is any way to set the textview attributes after we press the return key.

– Teja Nandamuri
Feb 11 '16 at 18:08





Yes. I agree. It is because at the point we set the text alignment to center, the previous text alignment is already broken, the new text alignment will be set after we type something. I will see if there is any way to set the textview attributes after we press the return key.

– Teja Nandamuri
Feb 11 '16 at 18:08













in the meantime I select your answer as right. vote up if you find something to check the textview attributes after return key

– user4385051
Feb 12 '16 at 16:19





in the meantime I select your answer as right. vote up if you find something to check the textview attributes after return key

– user4385051
Feb 12 '16 at 16:19



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35345523%2fstrange-alignment-in-uitextview%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20